Class: RubyLotus::Route
- Inherits:
-
Object
- Object
- RubyLotus::Route
- Defined in:
- lib/ruby_lotus/route.rb
Constant Summary collapse
- EXCLUDE_PATHS =
%w[rails assets cable historical_location].freeze
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path:, method:, name:, controller:, action:, params:, constraints:, id: nil) ⇒ Route
constructor
A new instance of Route.
Constructor Details
#initialize(path:, method:, name:, controller:, action:, params:, constraints:, id: nil) ⇒ Route
Returns a new instance of Route.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ruby_lotus/route.rb', line 6 def initialize(path:, method:, name:, controller:, action:, params:, constraints:, id: nil) @path = path @method = method @name = name @controller = controller @action = action @params = params @constraints = constraints @id = id if id end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
4 5 6 |
# File 'lib/ruby_lotus/route.rb', line 4 def action @action end |
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
4 5 6 |
# File 'lib/ruby_lotus/route.rb', line 4 def constraints @constraints end |
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
4 5 6 |
# File 'lib/ruby_lotus/route.rb', line 4 def controller @controller end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/ruby_lotus/route.rb', line 4 def id @id end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
4 5 6 |
# File 'lib/ruby_lotus/route.rb', line 4 def method @method end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/ruby_lotus/route.rb', line 4 def name @name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
4 5 6 |
# File 'lib/ruby_lotus/route.rb', line 4 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/ruby_lotus/route.rb', line 4 def path @path end |
Class Method Details
.from_rails_route(route, id:) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ruby_lotus/route.rb', line 22 def self.from_rails_route(route, id:) path = route.ast.to_s.gsub("(.:format)", "") return nil if path.match?(/#{EXCLUDE_PATHS.join('|')}/) method = route.verb name = route.name controller = route.defaults[:controller] action = route.defaults[:action] params = route.parts constraints = route.constraints new(path:, method:, name:, controller:, action:, params:, constraints:, id:) end |
.from_rails_routes ⇒ Object
17 18 19 20 |
# File 'lib/ruby_lotus/route.rb', line 17 def self.from_rails_routes routes = Rails.application.routes.routes routes.each_with_index.map { |route, id| from_rails_route(route, id:) }.compact end |