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.



7
8
9
# File 'lib/rswag/route_parser.rb', line 7

def initialize(controller)
  @controller = controller
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



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

def controller
  @controller
end

Instance Method Details

#routesObject



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

def routes
  ::Rails.application.routes.routes.select do |route|
    route.defaults[:controller] == controller
  end.each_with_object({}) do |route, tree|
    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