Class: Merb::Router::Behavior::Proxy Private
- Defined in:
- lib/merb-core/dispatch/router/behavior.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Proxy catches any methods and proxies them to the current behavior. This allows building routes without constantly having to catching the yielded behavior object
Instance Method Summary collapse
-
#initialize ⇒ Proxy
constructor
private
A new instance of Proxy.
-
#pop ⇒ Object
private
Removes the top-most behavior.
-
#push(behavior) ⇒ Object
private
Puts a behavior on the bottom of the stack.
-
#redirect(url, opts = {}) ⇒ Object
Generates a Rack redirection response.
-
#respond_to?(*args) ⇒ Boolean
private
Tests whether the top-most behavior responds to the arguments.
-
#url(name, *args) ⇒ Object
There are three possible ways to use this method.
Constructor Details
#initialize ⇒ Proxy
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Proxy.
21 22 23 |
# File 'lib/merb-core/dispatch/router/behavior.rb', line 21 def initialize @behaviors = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Proxies the method calls to the behavior.
Notes
Please refer to: ruby-doc.org/core/classes/Kernel.html#M005951
152 153 154 155 156 157 158 159 160 |
# File 'lib/merb-core/dispatch/router/behavior.rb', line 152 def method_missing(method, *args, &block) behavior = @behaviors.last if behavior.respond_to?(method) behavior.send(method, *args, &block) else super end end |
Instance Method Details
#pop ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Removes the top-most behavior.
Notes
This occurs at the end of a nested scope (namespace, etc).
41 42 43 |
# File 'lib/merb-core/dispatch/router/behavior.rb', line 41 def pop @behaviors.pop end |
#push(behavior) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Puts a behavior on the bottom of the stack.
Notes
The behaviors keep track of nested scopes.
31 32 33 |
# File 'lib/merb-core/dispatch/router/behavior.rb', line 31 def push(behavior) @behaviors.push(behavior) end |
#redirect(url, opts = {}) ⇒ Object
Generates a Rack redirection response.
Notes
Refer to Merb::Rack::Helpers.redirect for documentation.
139 140 141 |
# File 'lib/merb-core/dispatch/router/behavior.rb', line 139 def redirect(url, opts = {}) Merb::Rack::Helpers.redirect(url, opts) end |
#respond_to?(*args) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Tests whether the top-most behavior responds to the arguments.
Notes
Behaviors contain the actual functionality of the proxy.
51 52 53 |
# File 'lib/merb-core/dispatch/router/behavior.rb', line 51 def respond_to?(*args) super || @behaviors.last.respond_to?(*args) end |
#url(name, *args) ⇒ Object
There are three possible ways to use this method. First, if you have a named route, you can specify the route as the first parameter as a symbol and any paramters in a hash. Second, you can generate the default route by just passing the params hash, just passing the params hash. Finally, you can use the anonymous parameters. This allows you to specify the parameters to a named route in the order they appear in the router.
Parameters(Named Route)
- name<Symbol>
-
The name of the route.
- args<Hash>
-
Parameters for the route generation.
Parameters(Default Route)
- args<Hash>
-
Parameters for the route generation. This route will use the default route.
Parameters(Anonymous Parameters)
- name<Symbol>
-
The name of the route.
- args<Array>
-
An array of anonymous parameters to generate the route with. These parameters are assigned to the route parameters in the order that they are passed.
Returns
- String
-
The generated URL.
Examples
Named Route
Merb::Router.prepare do
match("/articles/:title").to(:controller => :articles, :action => :show).name("articles")
end
url(:articles, :title => “new_article”)
Default Route
Merb::Router.prepare do
default_routes
end
url(:controller => “articles”, :action => “new”)
Anonymous Paramters
Merb::Router.prepare do
match("/articles/:year/:month/:title").to(:controller => :articles, :action => :show).name("articles")
end
url(:articles, 2008, 10, “test_article”)
128 129 130 131 |
# File 'lib/merb-core/dispatch/router/behavior.rb', line 128 def url(name, *args) args << {} Merb::Router.url(name, *args) end |