Module: Resourcelogic::Urligence

Included in:
ActionController::Base
Defined in:
lib/resourcelogic/urligence.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



117
118
119
120
121
122
123
124
125
126
# File 'lib/resourcelogic/urligence.rb', line 117

def method_missing(method, *args, &block)
  if method.to_s =~ /^((.*)_)?(child_collection|parent_collection|sibling|sibling_collection)_(path|url)$/ || method.to_s =~ /^((.*)_)?(child|collection|object|parent)_(path|url)$/
    action = $2.blank? ? nil : $2.to_sym
    target = $3
    url_type = $4
    send("smart_#{url_type}", *send("#{target}_url_parts", action, *args))
  else
    super
  end
end

Class Method Details

.included(klass) ⇒ Object



3
4
5
# File 'lib/resourcelogic/urligence.rb', line 3

def self.included(klass)
  klass.helper_method :smart_url, :smart_path, :hash_for_smart_url, :hash_for_smart_path, :method_missing
end

Instance Method Details

#hash_for_smart_path(*url_parts) ⇒ Object



25
26
27
# File 'lib/resourcelogic/urligence.rb', line 25

def hash_for_smart_path(*url_parts)
  urligence(*url_parts.unshift(:hash_for).push(:path).push({:type => :hash}))
end

#hash_for_smart_url(*url_parts) ⇒ Object



21
22
23
# File 'lib/resourcelogic/urligence.rb', line 21

def hash_for_smart_url(*url_parts)
  urligence(*url_parts.unshift(:hash_for).push(:url).push({:type => :hash}))
end

#smart_path(*url_parts) ⇒ Object



14
15
16
17
18
19
# File 'lib/resourcelogic/urligence.rb', line 14

def smart_path(*url_parts)
  url_params = url_parts.extract_options!
  url_parts.push(:path)
  url_parts.push(url_params)
  urligence(*url_parts)
end

#smart_url(*url_parts) ⇒ Object



7
8
9
10
11
12
# File 'lib/resourcelogic/urligence.rb', line 7

def smart_url(*url_parts)
  url_params = url_parts.extract_options!
  url_parts.push(:url)
  url_parts.push(url_params)
  urligence(*url_parts)
end