module Roda::RodaPlugins::MultiRoute::ClassMethods

  1. lib/roda/plugins/multi_route.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/multi_route.rb, line 136
def freeze
  opts[:namespaced_routes].freeze
  opts[:namespaced_routes].each_value(&:freeze)
  super
end
inherited (subclass)

Copy the named routes into the subclass when inheriting.

[show source]
# File lib/roda/plugins/multi_route.rb, line 143
def inherited(subclass)
  super
  nsr = subclass.opts[:namespaced_routes]
  opts[:namespaced_routes].each{|k, v| nsr[k] = v.dup}
  subclass::RodaRequest.instance_variable_set(:@namespaced_route_regexps, {})
end
named_route (name, namespace=nil)

Return the named route with the given name.

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

The names for the currently stored named routes

[show source]
# File lib/roda/plugins/multi_route.rb, line 151
def named_routes(namespace=nil)
  routes = opts[:namespaced_routes][namespace]
  routes ? routes.keys : []
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/multi_route.rb, line 164
def route(name=nil, namespace=nil, &block)
  if name
    opts[:namespaced_routes][namespace] ||= {}
    opts[:namespaced_routes][namespace][name] = block
    self::RodaRequest.clear_named_route_regexp!(namespace)
  else
    super(&block)
  end
end