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
-
#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(ctrl, path, block) ⇒ RouteRefine
constructor
A new instance of RouteRefine.
- #rest ⇒ Object
Constructor Details
#initialize(ctrl, path, block) ⇒ RouteRefine
Returns a new instance of RouteRefine.
49 50 51 52 53 54 55 56 |
# File 'lib/flame/router.rb', line 49 def initialize(ctrl, path, block) @ctrl = ctrl @path = path || default_controller_path @routes = [] block.nil? ? defaults : instance_exec(&block) # p @routes @routes.sort! { |a, b| b[:path] <=> a[:path] } end |
Instance Attribute Details
#rest_routes ⇒ Object
Returns the value of attribute rest_routes.
32 33 34 |
# File 'lib/flame/router.rb', line 32 def rest_routes @rest_routes end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
33 34 35 |
# File 'lib/flame/router.rb', line 33 def routes @routes end |
Class Method Details
.http_methods ⇒ Object
35 36 37 |
# File 'lib/flame/router.rb', line 35 def self.http_methods [:GET, :POST, :PUT, :DELETE] end |
Instance Method Details
#defaults ⇒ Object
65 66 67 68 69 70 |
# File 'lib/flame/router.rb', line 65 def defaults @ctrl.public_instance_methods(false).each do |action| next if find_route_index(action: action) add_route(:GET, nil, action) end end |
#rest ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/flame/router.rb', line 72 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 |