lib/roda/plugins/multi_route.rb in roda-1.1.0 vs lib/roda/plugins/multi_route.rb in roda-1.2.0
- old
+ new
@@ -123,42 +123,40 @@
# routes/foo/baz.rb
# routes/foo/quux.rb
module MultiRoute
# Initialize storage for the named routes.
def self.configure(app)
- app.instance_exec do
- @namespaced_routes ||= {}
- app::RodaRequest.instance_variable_set(:@namespaced_route_regexps, {})
- end
+ app.opts[:namespaced_routes] ||= {}
+ app::RodaRequest.instance_variable_set(:@namespaced_route_regexps, {})
end
module ClassMethods
# Copy the named routes into the subclass when inheriting.
def inherited(subclass)
super
- nsr = subclass.instance_variable_set(:@namespaced_routes, {})
- @namespaced_routes.each{|k, v| nsr[k] = v.dup}
+ nsr = subclass.opts[:namespaced_routes]
+ opts[:namespaced_routes].each{|k, v| nsr[k] = v.dup}
subclass::RodaRequest.instance_variable_set(:@namespaced_route_regexps, {})
end
# The names for the currently stored named routes
def named_routes(namespace=nil)
- @namespaced_routes[namespace].keys
+ opts[:namespaced_routes][namespace].keys
end
# Return the named route with the given name.
def named_route(name, namespace=nil)
- @namespaced_routes[namespace][name]
+ opts[:namespaced_routes][namespace][name]
end
# 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.
def route(name=nil, namespace=nil, &block)
if name
- @namespaced_routes[namespace] ||= {}
- @namespaced_routes[namespace][name] = block
+ opts[:namespaced_routes][namespace] ||= {}
+ opts[:namespaced_routes][namespace][name] = block
self::RodaRequest.clear_named_route_regexp!(namespace)
else
super(&block)
end
end
@@ -197,10 +195,10 @@
end
end
# Dispatch to the named route with the given name.
def route(name, namespace=nil)
- scope.instance_exec(self, &self.class.roda_class.named_route(name, namespace))
+ scope.instance_exec(self, &roda_class.named_route(name, namespace))
end
end
end
register_plugin(:multi_route, MultiRoute)