Class: SwaggerYard::Rails::RouteInspector::JourneyRoutes

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

Instance Method Summary collapse

Constructor Details

#initialize(routes) ⇒ JourneyRoutes

Returns a new instance of JourneyRoutes.



12
13
14
# File 'lib/swagger_yard/rails/route_inspector.rb', line 12

def initialize(routes)
  @routes = routes
end

Instance Method Details

#call(yard_obj) ⇒ Object Also known as: []

Raises:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/swagger_yard/rails/route_inspector.rb', line 16

def call(yard_obj)
  return nil if skip_object?(yard_obj)

  info      = yard_info(yard_obj)
  route_arr = find_route(info)
  route     = route_arr.last
  method    = route.verb
  method    = method.source.gsub(/[$^]/, '') if method.respond_to?(:source)

  raise Error, "no http method: #{info.inspect}" if method.empty?

  path = route_arr.map do |r|
    r.parts.inject(r.ast.to_s) do |p,sym|
      p.sub(sym.inspect, "{#{sym}}")
    end
  end.join

  # FIXME: always remove format parameter?
  path = path.sub('(.{format})', '')

  [method, path]
end