Class: Generic::Routing
- Inherits:
-
Object
- Object
- Generic::Routing
- Defined in:
- lib/generic/routing.rb
Instance Attribute Summary collapse
-
#after_actions ⇒ Object
readonly
Returns the value of attribute after_actions.
-
#before_actions ⇒ Object
readonly
Returns the value of attribute before_actions.
-
#fail ⇒ Object
readonly
Returns the value of attribute fail.
-
#jr ⇒ Object
readonly
Returns the value of attribute jr.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(options) ⇒ Routing
constructor
A new instance of Routing.
- #ready(rd) ⇒ Object
Constructor Details
#initialize(options) ⇒ Routing
Returns a new instance of Routing.
45 46 47 48 49 50 51 |
# File 'lib/generic/routing.rb', line 45 def initialize() @scope = [:scope] @before_actions = [:before_actions] @after_actions = [:after_actions] @fail = [:fail] ready([:rd]) end |
Instance Attribute Details
#after_actions ⇒ Object (readonly)
Returns the value of attribute after_actions.
43 44 45 |
# File 'lib/generic/routing.rb', line 43 def after_actions @after_actions end |
#before_actions ⇒ Object (readonly)
Returns the value of attribute before_actions.
43 44 45 |
# File 'lib/generic/routing.rb', line 43 def before_actions @before_actions end |
#fail ⇒ Object (readonly)
Returns the value of attribute fail.
43 44 45 |
# File 'lib/generic/routing.rb', line 43 def fail @fail end |
#jr ⇒ Object (readonly)
Returns the value of attribute jr.
43 44 45 |
# File 'lib/generic/routing.rb', line 43 def jr @jr end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
43 44 45 |
# File 'lib/generic/routing.rb', line 43 def scope @scope end |
Instance Method Details
#call(env) ⇒ Object
53 54 55 56 57 58 59 60 |
# 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) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/generic/routing.rb', line 62 def ready(rd) routes = Genericer::DJRoutes.new @jr = Genericer::DJRouter.new(routes, {}) rd.each do |path, , handler| pat = Genericer::DJJourner.new(path) guard = .fetch(:guard, {}) defaults = .fetch(:defaults, {}) @jr.routes.add_route(Generic::InsEval.hand(scope, handler, before_actions, after_actions), pat, guard, defaults) end end |