Class: SwaggerDocsGenerator::Extractor

Inherits:
Object
  • Object
show all
Defined in:
lib/swagger_docs_generator/extractor.rb

Overview

# Extractor routes info

Give information about routes

Instance Method Summary collapse

Constructor Details

#initialize(controller, action) ⇒ Extractor

Returns a new instance of Extractor.



10
11
12
13
14
# File 'lib/swagger_docs_generator/extractor.rb', line 10

def initialize(controller, action)
  @action = action
  @controller = controller
  @routes = Rails.application.routes.routes
end

Instance Method Details

#pathObject

Extract path to routes and change format to parameter path



24
25
26
27
28
29
30
31
# File 'lib/swagger_docs_generator/extractor.rb', line 24

def path
  router do |route|
    route.path.spec.to_s.gsub('(.:format)',
                              '.json').gsub(/:[a-z1-9_A-Z]*/) do |word|
      "{#{word.delete(':')}}"
    end
  end
end

#verbObject

Extract verb to routes



17
18
19
20
21
# File 'lib/swagger_docs_generator/extractor.rb', line 17

def verb
  router do |route|
    route.verb.source.to_s.delete('$' + '^')
  end
end