18: def urligence(*objects)
19: config = {}
20: config.merge!(objects.pop) if objects.last.is_a?(Hash)
21:
22: objects.reject! { |object| object.nil? }
23:
24: url_fragments = objects.collect do |obj|
25: if obj.is_a? Symbol
26: obj
27: elsif obj.is_a? Array
28: obj.first
29: else
30: obj.class.name.underscore.to_sym
31: end
32: end
33:
34: unless config[:type] == :hash
35: send url_fragments.join("_"), *objects.flatten.select { |obj| !obj.is_a? Symbol }
36: else
37: params = {}
38: unparsed_params = objects.select { |obj| !obj.is_a? Symbol }
39: unparsed_params.each_with_index do |obj, i|
40: unless i == (unparsed_params.length-1)
41: params.merge!((obj.is_a? Array) ? {"#{obj.first}_id".to_sym => obj[1].to_param} : {"#{obj.class.name.underscore}_id".to_sym => obj.to_param})
42: else
43: params.merge!((obj.is_a? Array) ? {:id => obj[1].to_param} : {:id => obj.to_param})
44: end
45: end
46:
47: send url_fragments.join("_"), params
48: end
49: end