Class: RailsDevtools::Routes::RouteInfo

Inherits:
Object
  • Object
show all
Defined in:
app/models/rails_devtools/routes/route_info.rb

Constant Summary collapse

RedirectionInfo =
Data.define(:status, :block)

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#idObject (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

Returns:

  • (Boolean)


75
76
77
# File 'app/models/rails_devtools/routes/route_info.rb', line 75

def controller?
  [inline?, redirection?, rack_app?].none?
end

#controller_infoObject



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

Returns:

  • (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_infoObject



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

Returns:

  • (Boolean)


71
72
73
# File 'app/models/rails_devtools/routes/route_info.rb', line 71

def inline?
  endpoint.include?("Proc/Lambda")
end

#kindObject



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

#nameObject



28
29
30
# File 'app/models/rails_devtools/routes/route_info.rb', line 28

def name
  @name ||= route_name
end

#pathObject



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

Returns:

  • (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

Returns:

  • (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_infoObject



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

#segmentsObject



17
18
19
# File 'app/models/rails_devtools/routes/route_info.rb', line 17

def segments
  @wrapped_route.parts.reject { |p| p == :format }
end

#verbObject



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