Class: RailsDevtools::Routes::RouteInfo
- Inherits:
-
Object
- Object
- RailsDevtools::Routes::RouteInfo
- Defined in:
- app/models/rails_devtools/routes/route_info.rb
Constant Summary collapse
- RedirectionInfo =
Data.define(:status, :block)
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #controller? ⇒ Boolean
- #controller_info ⇒ Object
- #engine? ⇒ Boolean
- #engine_info ⇒ Object
-
#initialize(route, id:, engine: "Application") ⇒ RouteInfo
constructor
A new instance of RouteInfo.
- #inline? ⇒ Boolean
- #kind ⇒ Object
- #name ⇒ Object
- #path ⇒ Object
- #rack_app? ⇒ Boolean
- #redirection? ⇒ Boolean
- #redirection_info ⇒ Object
- #segments ⇒ Object
- #verb ⇒ Object
Constructor Details
#initialize(route, id:, engine: "Application") ⇒ RouteInfo
Returns a new instance of RouteInfo.
8 9 10 11 12 13 |
# File 'app/models/rails_devtools/routes/route_info.rb', line 8 def initialize(route, id:, engine: "Application") @route = route @wrapped_route = ActionDispatch::Routing::RouteWrapper.new(route) @engine = engine @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'app/models/rails_devtools/routes/route_info.rb', line 6 def id @id end |
Instance Method Details
#controller? ⇒ Boolean
75 76 77 |
# File 'app/models/rails_devtools/routes/route_info.rb', line 75 def controller? [inline?, redirection?, rack_app?].none? end |
#controller_info ⇒ Object
21 22 23 24 25 26 |
# File 'app/models/rails_devtools/routes/route_info.rb', line 21 def controller_info @controller_info ||= ControllerInfo.new( controller_name: controller, action: action ) end |
#engine? ⇒ Boolean
47 48 49 |
# File 'app/models/rails_devtools/routes/route_info.rb', line 47 def engine? @route.app.respond_to?(:engine?) && @route.app.engine? end |
#engine_info ⇒ Object
95 96 97 |
# File 'app/models/rails_devtools/routes/route_info.rb', line 95 def engine_info @engine_info ||= EngineInfo.new(@engine) end |
#inline? ⇒ Boolean
71 72 73 |
# File 'app/models/rails_devtools/routes/route_info.rb', line 71 def inline? endpoint.include?("Proc/Lambda") end |
#kind ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/models/rails_devtools/routes/route_info.rb', line 32 def kind @kind ||= if engine? "engine" elsif rack_app? "rack_app" elsif redirection? "redirection" elsif inline? "inline" else "controller" end end |
#name ⇒ Object
28 29 30 |
# File 'app/models/rails_devtools/routes/route_info.rb', line 28 def name @name ||= route_name end |
#path ⇒ Object
90 91 92 93 |
# File 'app/models/rails_devtools/routes/route_info.rb', line 90 def path return @wrapped_route.path if @engine == "Application" engine_info.path + @wrapped_route.path end |
#rack_app? ⇒ Boolean
62 63 64 65 66 67 68 69 |
# File 'app/models/rails_devtools/routes/route_info.rb', line 62 def rack_app? return false if inline? return false if redirection? return false if engine? @route.app.app.respond_to?(:call) && !@route.app.app.is_a?(ActionDispatch::Routing::RouteSet) end |
#redirection? ⇒ Boolean
56 57 58 59 60 |
# File 'app/models/rails_devtools/routes/route_info.rb', line 56 def redirection? return false if inline? @route.app&.app.respond_to?(:redirect?) && @route.app.app.redirect? end |
#redirection_info ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'app/models/rails_devtools/routes/route_info.rb', line 81 def redirection_info return unless redirection? @redirection_info ||= RedirectionInfo.new( status: @route.app.app.status, block: @route.app.app.block ) end |
#segments ⇒ Object
17 18 19 |
# File 'app/models/rails_devtools/routes/route_info.rb', line 17 def segments @wrapped_route.parts.reject { |p| p == :format } end |
#verb ⇒ Object
51 52 53 54 |
# File 'app/models/rails_devtools/routes/route_info.rb', line 51 def verb return "?" if rack_app? || engine? @wrapped_route.verb.presence || "ALL" end |