Class: SwaggerDocsGenerator::Sort
- Inherits:
-
Object
- Object
- SwaggerDocsGenerator::Sort
- Defined in:
- lib/swagger_docs_generator/metadata/sort.rb
Overview
Sort routes in hash before writing in JSON file
Instance Method Summary collapse
-
#initialize(hash) ⇒ Sort
constructor
A new instance of Sort.
-
#sort_by_path ⇒ Object
Sort routes by path.
-
#sort_by_tag ⇒ Object
Sort routes by tags.
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_path ⇒ Object
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_tag ⇒ Object
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 |