Class: LazyApiDoc::Generator
- Inherits:
-
Object
- Object
- LazyApiDoc::Generator
- Defined in:
- lib/lazy_api_doc/generator.rb
Constant Summary collapse
- EXCLUDED_PARAMS =
["controller", "action", "format"].freeze
Instance Attribute Summary collapse
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
Instance Method Summary collapse
- #add(example) ⇒ Object
- #clear ⇒ Object
-
#initialize ⇒ Generator
constructor
A new instance of Generator.
- #result ⇒ Object
Constructor Details
#initialize ⇒ Generator
Returns a new instance of Generator.
9 10 11 |
# File 'lib/lazy_api_doc/generator.rb', line 9 def initialize @examples = [] end |
Instance Attribute Details
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
7 8 9 |
# File 'lib/lazy_api_doc/generator.rb', line 7 def examples @examples end |
Instance Method Details
#add(example) ⇒ Object
13 14 15 16 17 |
# File 'lib/lazy_api_doc/generator.rb', line 13 def add(example) return if example['controller'] == "anonymous" # don't handle virtual controllers @examples << example end |
#clear ⇒ Object
19 20 21 |
# File 'lib/lazy_api_doc/generator.rb', line 19 def clear @examples = [] end |
#result ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/lazy_api_doc/generator.rb', line 23 def result result = {} @examples.map { |example| OpenStruct.new(example) }.sort_by(&:source_location) .group_by { |example| ::LazyApiDoc::RouteParser.find_by(example) } .each do |route, examples| next if route.nil? # TODO: think about adding such cases to log first = examples.first doc_path = route['doc_path'] result[doc_path] ||= {} result[doc_path].merge!(example_group(first, examples, route)) end result end |