Module Urligence
In: ../lib/urligence.rb

Methods

Public Instance methods

[Source]

    # File ../lib/urligence.rb, line 14
14:   def hash_for_smart_path(*objects)
15:     urligence(*objects.unshift(:hash_for).push(:path).push({:type => :hash}))
16:   end

[Source]

    # File ../lib/urligence.rb, line 10
10:   def hash_for_smart_url(*objects)
11:     urligence(*objects.unshift(:hash_for).push(:url).push({:type => :hash}))
12:   end

[Source]

   # File ../lib/urligence.rb, line 6
6:   def smart_path(*objects)
7:     urligence(*objects.push(:path))
8:   end

[Source]

   # File ../lib/urligence.rb, line 2
2:   def smart_url(*objects)
3:     urligence(*objects.push(:url))
4:   end

[Source]

    # File ../lib/urligence.rb, line 18
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

[Validate]