Class: Flame::Router::RouteRefine
- Inherits:
-
Object
- Object
- Flame::Router::RouteRefine
- Defined in:
- lib/flame/router.rb
Overview
Helper module for routing refine
Constant Summary collapse
- HOOK_TYPES =
[:before, :after, :error].freeze
Instance Attribute Summary collapse
-
#ctrl ⇒ Object
readonly
Returns the value of attribute ctrl.
-
#hooks ⇒ Object
readonly
Returns the value of attribute hooks.
-
#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
- #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.
82 83 84 85 86 87 88 89 |
# File 'lib/flame/router.rb', line 82 def initialize(router, ctrl, path, block) @router = router @ctrl = ctrl @path = path || @ctrl.default_path @routes = [] @hooks = HOOK_TYPES.each_with_object({}) { |type, hash| hash[type] = {} } execute(&block) end |
Instance Attribute Details
#ctrl ⇒ Object (readonly)
Returns the value of attribute ctrl.
64 65 66 |
# File 'lib/flame/router.rb', line 64 def ctrl @ctrl end |
#hooks ⇒ Object (readonly)
Returns the value of attribute hooks.
64 65 66 |
# File 'lib/flame/router.rb', line 64 def hooks @hooks end |
#rest_routes ⇒ Object
Returns the value of attribute rest_routes.
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.
64 65 66 |
# File 'lib/flame/router.rb', line 64 def routes @routes end |
Class Method Details
.http_methods ⇒ Object
68 69 70 |
# File 'lib/flame/router.rb', line 68 def self.http_methods [:GET, :POST, :PUT, :DELETE] end |
Instance Method Details
#defaults ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/flame/router.rb', line 110 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
128 129 130 131 132 133 134 |
# File 'lib/flame/router.rb', line 128 def mount(ctrl, path = nil, &block) path = path_merge( @path, (path || ctrl.default_path(true)) ) @router.add_controller(ctrl, path, block) end |
#rest ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/flame/router.rb', line 118 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 |