Class: Flame::Router::RouteRefine
- Inherits:
-
Object
- Object
- Flame::Router::RouteRefine
- Defined in:
- lib/flame/router.rb
Overview
Helper class for controller routing refine
Instance Attribute Summary collapse
-
#ctrl ⇒ Object
readonly
Returns the value of attribute ctrl.
-
#rest_routes ⇒ Object
Defaults REST routes (methods, pathes, controllers actions).
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
-
#defaults ⇒ Object
Assign remaining methods of the controller to defaults pathes and HTTP methods.
-
#initialize(router, ctrl, path, block) ⇒ RouteRefine
constructor
A new instance of RouteRefine.
-
#mount(ctrl, path = nil) { ... } ⇒ Object
Mount controller inside other (parent) controller.
-
#rest ⇒ Object
Assign methods of the controller to REST architecture.
Constructor Details
#initialize(router, ctrl, path, block) ⇒ RouteRefine
Returns a new instance of RouteRefine.
73 74 75 76 77 78 79 |
# File 'lib/flame/router.rb', line 73 def initialize(router, ctrl, path, block) @router = router @ctrl = ctrl @path = path || @ctrl.default_path @routes = [] execute(&block) end |
Instance Attribute Details
#ctrl ⇒ Object (readonly)
Returns the value of attribute ctrl.
60 61 62 |
# File 'lib/flame/router.rb', line 60 def ctrl @ctrl end |
#rest_routes ⇒ Object
Defaults REST routes (methods, pathes, controllers actions)
63 64 65 |
# File 'lib/flame/router.rb', line 63 def rest_routes @rest_routes end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
60 61 62 |
# File 'lib/flame/router.rb', line 60 def routes @routes end |
Instance Method Details
#defaults ⇒ Object
Assign remaining methods of the controller
to defaults pathes and HTTP methods
112 113 114 115 116 117 118 |
# File 'lib/flame/router.rb', line 112 def defaults rest @ctrl.actions.each do |action| next if find_route_index(action: action) send(:GET.downcase, action) end end |
#mount(ctrl, path = nil) { ... } ⇒ Object
Mount controller inside other (parent) controller
134 135 136 137 |
# File 'lib/flame/router.rb', line 134 def mount(ctrl, path = nil, &block) path = Flame::Path.merge(@path, path || ctrl.default_path) @router.add_controller(ctrl, path, &block) end |
#rest ⇒ Object
Assign methods of the controller to REST architecture
121 122 123 124 125 126 127 128 |
# File 'lib/flame/router.rb', line 121 def rest rest_routes.each do |rest_route| action = rest_route[:action] next if !@ctrl.actions.include?(action) || find_route_index(action: action) send(*rest_route.values.map(&:downcase)) end end |