Module: Roda::RodaPlugins::MultiRoute::ClassMethods
- Defined in:
- lib/roda/plugins/multi_route.rb
Instance Method Summary collapse
-
#inherited(subclass) ⇒ Object
Copy the named routes into the subclass when inheriting.
-
#named_route(name, namespace = nil) ⇒ Object
Return the named route with the given name.
-
#named_routes(namespace = nil) ⇒ Object
The names for the currently stored named routes.
-
#route(name = nil, namespace = nil, &block) ⇒ Object
If the given route has a name, treat it as a named route and store the route block.
Instance Method Details
#inherited(subclass) ⇒ Object
Copy the named routes into the subclass when inheriting.
136 137 138 139 140 141 |
# File 'lib/roda/plugins/multi_route.rb', line 136 def inherited(subclass) super nsr = subclass.instance_variable_set(:@namespaced_routes, {}) @namespaced_routes.each{|k, v| nsr[k] = v.dup} subclass::RodaRequest.instance_variable_set(:@namespaced_route_regexps, {}) end |
#named_route(name, namespace = nil) ⇒ Object
Return the named route with the given name.
149 150 151 |
# File 'lib/roda/plugins/multi_route.rb', line 149 def named_route(name, namespace=nil) @namespaced_routes[namespace][name] end |
#named_routes(namespace = nil) ⇒ Object
The names for the currently stored named routes
144 145 146 |
# File 'lib/roda/plugins/multi_route.rb', line 144 def named_routes(namespace=nil) @namespaced_routes[namespace].keys end |
#route(name = nil, namespace = nil, &block) ⇒ Object
If the given route has a name, treat it as a named route and store the route block. Otherwise, this is the main route, so call super.
156 157 158 159 160 161 162 163 164 |
# File 'lib/roda/plugins/multi_route.rb', line 156 def route(name=nil, namespace=nil, &block) if name @namespaced_routes[namespace] ||= {} @namespaced_routes[namespace][name] = block self::RodaRequest.clear_named_route_regexp!(namespace) else super(&block) end end |