class SwaggerDocsGenerator::Sort
Sort
routes in hash before writing in JSON file
Public Class Methods
new(hash)
click to toggle source
# File lib/swagger_docs_generator/metadata/sort.rb, line 8 def initialize(hash) @routes = hash @readme = { README: @routes[:paths]['README'] } end
Public Instance Methods
sort_by_path()
click to toggle source
Sort
routes by path
# 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()
click to toggle source
Sort
routes by tags
# 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
Private Instance Methods
place_readme_first(hash)
click to toggle source
# File lib/swagger_docs_generator/metadata/sort.rb, line 29 def place_readme_first(hash) if hash.key?('README') hash.delete('README') { paths: @readme.merge!(hash) } else { paths: hash } end end