Class: Rswag::RouteParser

Inherits:
Object
  • Object
show all
Defined in:
lib/rswag/route_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ RouteParser

Returns a new instance of RouteParser.



5
6
7
# File 'lib/rswag/route_parser.rb', line 5

def initialize(controller)
  @controller = controller
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



3
4
5
# File 'lib/rswag/route_parser.rb', line 3

def controller
  @controller
end

Instance Method Details

#routesObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rswag/route_parser.rb', line 9

def routes
  ::Rails.application.routes.routes.select do |route|
    route.defaults[:controller] == controller
  end.reduce({}) do |tree, route|
    path = path_from(route)
    verb = verb_from(route)
    tree[path] ||= { params: params_from(route), actions: {} }
    tree[path][:actions][verb] = { summary: summary_from(route) }
    tree
  end
end