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.
Class Method Summary collapse
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.
76 77 78 79 80 81 82 |
# File 'lib/flame/router.rb', line 76 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.
59 60 61 |
# File 'lib/flame/router.rb', line 59 def ctrl @ctrl end |
#rest_routes ⇒ Object
Defaults REST routes (methods, pathes, controllers actions)
66 67 68 |
# File 'lib/flame/router.rb', line 66 def rest_routes @rest_routes end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
59 60 61 |
# File 'lib/flame/router.rb', line 59 def routes @routes end |
Class Method Details
.http_methods ⇒ Object
61 62 63 |
# File 'lib/flame/router.rb', line 61 def self.http_methods [:GET, :POST, :PUT, :DELETE] end |
Instance Method Details
#defaults ⇒ Object
Assign remaining methods of the controller
to defaults pathes and HTTP methods
116 117 118 119 120 121 122 |
# File 'lib/flame/router.rb', line 116 def defaults rest @ctrl.public_instance_methods(false).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
138 139 140 141 |
# File 'lib/flame/router.rb', line 138 def mount(ctrl, path = nil, &block) path = Route.path_merge(@path, path || ctrl.default_path) @router.add_controller(ctrl, path, block) end |
#rest ⇒ Object
Assign methods of the controller to REST architecture
125 126 127 128 129 130 131 132 |
# File 'lib/flame/router.rb', line 125 def rest rest_routes.each do |rest_route| action = rest_route[:action] next unless @ctrl.public_instance_methods.include?(action) && find_route_index(action: action).nil? send(*rest_route.values.map(&:downcase), prefix: true) end end |