Class: Flame::Router::RouteRefine
- Inherits:
-
Object
- Object
- Flame::Router::RouteRefine
- Defined in:
- lib/flame/router.rb
Overview
Helper module for routing refine
Instance Attribute Summary collapse
-
#afters ⇒ Object
readonly
Returns the value of attribute afters.
-
#befores ⇒ Object
readonly
Returns the value of attribute befores.
-
#ctrl ⇒ Object
readonly
Returns the value of attribute ctrl.
-
#rest_routes ⇒ Object
Returns the value of attribute rest_routes.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Class Method Summary collapse
Instance Method Summary collapse
- #after(actions = :*, action = nil, &block) ⇒ Object
- #before(actions = :*, action = nil, &block) ⇒ Object
- #defaults ⇒ Object
-
#initialize(router, ctrl, path, block) ⇒ RouteRefine
constructor
A new instance of RouteRefine.
- #mount(ctrl, path = nil, &block) ⇒ Object
- #rest ⇒ Object
Constructor Details
#initialize(router, ctrl, path, block) ⇒ RouteRefine
Returns a new instance of RouteRefine.
73 74 75 76 77 78 79 80 |
# File 'lib/flame/router.rb', line 73 def initialize(router, ctrl, path, block) @router = router @ctrl = ctrl @path = path || @ctrl.default_path @routes = [] @befores, @afters = Array.new(2) { {} } execute(&block) end |
Instance Attribute Details
#afters ⇒ Object (readonly)
Returns the value of attribute afters.
57 58 59 |
# File 'lib/flame/router.rb', line 57 def afters @afters end |
#befores ⇒ Object (readonly)
Returns the value of attribute befores.
57 58 59 |
# File 'lib/flame/router.rb', line 57 def befores @befores end |
#ctrl ⇒ Object (readonly)
Returns the value of attribute ctrl.
57 58 59 |
# File 'lib/flame/router.rb', line 57 def ctrl @ctrl end |
#rest_routes ⇒ Object
Returns the value of attribute rest_routes.
56 57 58 |
# File 'lib/flame/router.rb', line 56 def rest_routes @rest_routes end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
57 58 59 |
# File 'lib/flame/router.rb', line 57 def routes @routes end |
Class Method Details
.http_methods ⇒ Object
59 60 61 |
# File 'lib/flame/router.rb', line 59 def self.http_methods [:GET, :POST, :PUT, :DELETE] end |
Instance Method Details
#after(actions = :*, action = nil, &block) ⇒ Object
98 99 100 101 |
# File 'lib/flame/router.rb', line 98 def after(actions = :*, action = nil, &block) actions = [actions] unless actions.is_a?(Array) actions.each { |a| (@afters[a] ||= []).push(action || block) } end |
#before(actions = :*, action = nil, &block) ⇒ Object
93 94 95 96 |
# File 'lib/flame/router.rb', line 93 def before(actions = :*, action = nil, &block) actions = [actions] unless actions.is_a?(Array) actions.each { |a| (@befores[a] ||= []).push(action || block) } end |
#defaults ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/flame/router.rb', line 103 def defaults rest @ctrl.public_instance_methods(false).each do |action| next if find_route_index(action: action) add_route(:GET, nil, action) end end |
#mount(ctrl, path = nil, &block) ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/flame/router.rb', line 121 def mount(ctrl, path = nil, &block) path = path_merge( @path, (path || ctrl.default_path(true)) ) @router.add_controller(ctrl, path, block) end |
#rest ⇒ Object
111 112 113 114 115 116 117 118 119 |
# File 'lib/flame/router.rb', line 111 def rest rest_routes.each do |rest_route| action = rest_route[:action] if @ctrl.public_instance_methods.include?(action) && find_route_index(action: action).nil? add_route(*rest_route.values, true) end end end |