module Roda::RodaPlugins::NamedRoutes::ClassMethods

  1. lib/roda/plugins/named_routes.rb

Methods

Public Instance

  1. freeze
  2. inherited
  3. named_route
  4. named_routes
  5. route

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
115 def freeze
116   opts[:namespaced_routes].freeze.each_value(&:freeze)
117   super
118 end
inherited(subclass)

Copy the named routes into the subclass when inheriting.

[show source]
    # File lib/roda/plugins/named_routes.rb
121 def inherited(subclass)
122   super
123   nsr = subclass.opts[:namespaced_routes]
124   opts[:namespaced_routes].each{|k, v| nsr[k] = v.dup}
125 end
named_route(name, namespace=nil)

Return the named route with the given name.

[show source]
    # File lib/roda/plugins/named_routes.rb
136 def named_route(name, namespace=nil)
137   opts[:namespaced_routes][namespace][name]
138 end
named_routes(namespace=nil)

The names for the currently stored named routes

[show source]
    # File lib/roda/plugins/named_routes.rb
128 def named_routes(namespace=nil)
129   unless routes = opts[:namespaced_routes][namespace]
130     raise RodaError, "unsupported named_routes namespace used: #{namespace.inspect}"
131   end
132   routes.keys
133 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
143 def route(name=nil, namespace=nil, &block)
144   if name
145     routes = opts[:namespaced_routes][namespace] ||= {}
146     if block
147       routes[name] = define_roda_method(routes[name] || "named_routes_#{namespace}_#{name}", 1, &convert_route_block(block))
148     elsif meth = routes.delete(name)
149       remove_method(meth)
150     end
151   else
152     super(&block)
153   end
154 end