Class: Swagger::Grape::Routes

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-swagger/grape/routes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(routes) ⇒ Routes

Returns a new instance of Routes.



9
10
11
12
13
# File 'lib/ruby-swagger/grape/routes.rb', line 9

def initialize(routes)
  @routes = routes
  @types = []
  @scopes = []
end

Instance Attribute Details

#scopesObject (readonly)

Returns the value of attribute scopes.



7
8
9
# File 'lib/ruby-swagger/grape/routes.rb', line 7

def scopes
  @scopes
end

#typesObject (readonly)

Returns the value of attribute types.



7
8
9
# File 'lib/ruby-swagger/grape/routes.rb', line 7

def types
  @types
end

Instance Method Details

#to_swaggerObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ruby-swagger/grape/routes.rb', line 15

def to_swagger
  swagger = Swagger::Data::Paths.new
  paths = {}

  @routes.each do |route|
    next if route.route_hidden == true # implement custom "hidden" extension

    swagger_path_name = swagger_path_name(route)
    paths[swagger_path_name] ||= Swagger::Grape::RoutePath.new(swagger_path_name)
    paths[swagger_path_name].add_operation(route)
  end

  paths.each do |path_name, path|
    swagger.add_path(path_name, path.to_swagger)
    @types = (@types | path.types).uniq
    @scopes = (@scopes | path.scopes).uniq
  end

  swagger
end