class Generic::Routing

Attributes

after_actions[R]
before_actions[R]
fail[R]
jr[R]
scope[R]

Public Class Methods

new(options) click to toggle source
# File lib/generic/routing.rb, line 45
def initialize(options)
  @scope    = options[:scope]
  @before_actions   = options[:before_actions]
  @after_actions    = options[:after_actions]
  @fail       = options[:fail]
  ready(options[:rd])
end

Public Instance Methods

call(env) click to toggle source
# File lib/generic/routing.rb, line 53
def call(env)
  response = jr.call(env)
  if response[0] == 404 and fail
    fail.call(env)
  else
    response
  end
end
ready(rd) click to toggle source
# File lib/generic/routing.rb, line 62
def ready(rd)
  routes = Genericer::DJRoutes.new
  @jr = Genericer::DJRouter.new(routes, {})
  rd.each do |path, options, handler|
    pat         = Genericer::DJJourner.new(path)
    guard       = options.fetch(:guard, {})
    defaults    = options.fetch(:defaults, {})
    @jr.routes.add_route(Generic::InsEval.hand(scope, handler, before_actions, after_actions),
                              pat,
                              guard,
                              defaults)
  end
end