Class: Caliper::RouteInspector

Inherits:
Object
  • Object
show all
Defined in:
lib/caliper/route_inspector.rb

Instance Method Summary collapse

Constructor Details

#initializeRouteInspector

Returns a new instance of RouteInspector.



69
70
71
# File 'lib/caliper/route_inspector.rb', line 69

def initialize
  @engines = Hash.new
end

Instance Method Details

#collect_engine_routes(route) ⇒ Object



91
92
93
94
95
96
97
98
99
100
# File 'lib/caliper/route_inspector.rb', line 91

def collect_engine_routes(route)
  name = route.endpoint
  return unless route.engine?
  return if @engines[name]

  routes = route.rack_app.routes
  if routes.is_a?(ActionDispatch::Routing::RouteSet)
    @engines[name] = collect_routes(routes.routes)
  end
end

#collect_routes(routes) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/caliper/route_inspector.rb', line 79

def collect_routes(routes)
  routes = routes.collect do |route|
    RouteWrapper.new(route)
  end.reject do |route|
    route.internal?
  end.collect do |route|
    collect_engine_routes(route)

    {:name => route.name, :verb => route.verb, :path => route.path, :reqs => route.reqs } unless route.reqs.nil?
  end.compact
end

#routes(all_routes) ⇒ Object



73
74
75
76
77
# File 'lib/caliper/route_inspector.rb', line 73

def routes(all_routes)
  routes = collect_routes(all_routes)

  routes #+ routes_for_engines
end

#routes_for_enginesObject



102
103
104
105
106
# File 'lib/caliper/route_inspector.rb', line 102

def routes_for_engines
  @engines.map do |name, routes|
    formatted_routes(routes)
  end.flatten
end