Class: SwaggerDocsGenerator::Sort

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

Overview

Sort routes in hash before writing in JSON file

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Sort

Returns a new instance of Sort.



8
9
10
11
# File 'lib/swagger_docs_generator/metadata/sort.rb', line 8

def initialize(hash)
  @routes = hash
  @readme = { README: @routes[:paths]['README'] }
end

Instance Method Details

#sort_by_pathObject

Sort routes by path



14
15
16
17
# File 'lib/swagger_docs_generator/metadata/sort.rb', line 14

def sort_by_path
  by_path = Hash[@routes[:paths].sort]
  place_readme_first(by_path)
end

#sort_by_tagObject

Sort routes by tags



20
21
22
23
24
25
# File 'lib/swagger_docs_generator/metadata/sort.rb', line 20

def sort_by_tag
  by_tag = Hash[@routes[:paths].sort_by do |_key, value|
    value.first[1]['tags']
  end]
  place_readme_first(by_tag)
end