Public Instance methods
freeze()
Freeze the namespaced routes so that there can be no thread safety issues at runtime.
[show source]
# File lib/roda/plugins/named_routes.rb 117 def freeze 118 namespaced_routes.freeze.each_value(&:freeze) 119 super 120 end
inherited(subclass)
Copy the named routes into the subclass when inheriting.
[show source]
# File lib/roda/plugins/named_routes.rb 123 def inherited(subclass) 124 super 125 nsr = subclass.namespaced_routes 126 namespaced_routes.each{|k, v| nsr[k] = v.dup} 127 end
named_route(name, namespace=nil)
Return the named route with the given name.
[show source]
# File lib/roda/plugins/named_routes.rb 138 def named_route(name, namespace=nil) 139 namespaced_routes[namespace][name] 140 end
named_routes(namespace=nil)
The names for the currently stored named routes
[show source]
# File lib/roda/plugins/named_routes.rb 130 def named_routes(namespace=nil) 131 unless routes = namespaced_routes[namespace] 132 raise RodaError, "unsupported named_routes namespace used: #{namespace.inspect}" 133 end 134 routes.keys 135 end
route(name=nil, namespace=nil, &block)
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.
[show source]
# File lib/roda/plugins/named_routes.rb 145 def route(name=nil, namespace=nil, &block) 146 if name 147 routes = namespaced_routes[namespace] ||= {} 148 if block 149 routes[name] = define_roda_method(routes[name] || "named_routes_#{namespace}_#{name}", 1, &convert_route_block(block)) 150 elsif meth = routes.delete(name) 151 remove_method(meth) 152 end 153 else 154 super(&block) 155 end 156 end