module Roda::RodaPlugins::NamedRoutes::ClassMethods
Public Instance Methods
Source
# File lib/roda/plugins/named_routes.rb, line 115 def freeze opts[:namespaced_routes].freeze.each_value(&:freeze) super end
Freeze the namespaced routes so that there can be no thread safety issues at runtime.
Calls superclass method
Source
# File lib/roda/plugins/named_routes.rb, line 121 def inherited(subclass) super nsr = subclass.opts[:namespaced_routes] opts[:namespaced_routes].each{|k, v| nsr[k] = v.dup} end
Copy the named routes into the subclass when inheriting.
Calls superclass method
Source
# File lib/roda/plugins/named_routes.rb, line 136 def named_route(name, namespace=nil) opts[:namespaced_routes][namespace][name] end
Return the named route with the given name.
Source
# File lib/roda/plugins/named_routes.rb, line 128 def named_routes(namespace=nil) unless routes = opts[:namespaced_routes][namespace] raise RodaError, "unsupported named_routes namespace used: #{namespace.inspect}" end routes.keys end
The names for the currently stored named routes
Source
# File lib/roda/plugins/named_routes.rb, line 143 def route(name=nil, namespace=nil, &block) if name routes = opts[:namespaced_routes][namespace] ||= {} if block routes[name] = define_roda_method(routes[name] || "named_routes_#{namespace}_#{name}", 1, &convert_route_block(block)) elsif meth = routes.delete(name) remove_method(meth) end else super(&block) end 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.
Calls superclass method