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.
10 11 12 |
# File 'lib/lazy_api_doc/generator.rb', line 10 def initialize @examples = [] end |
Instance Attribute Details
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
8 9 10 |
# File 'lib/lazy_api_doc/generator.rb', line 8 def examples @examples end |
Instance Method Details
#add(example) ⇒ Object
14 15 16 17 18 |
# File 'lib/lazy_api_doc/generator.rb', line 14 def add(example) return if example['controller'] == "anonymous" # don't handle virtual controllers @examples << example end |
#clear ⇒ Object
20 21 22 |
# File 'lib/lazy_api_doc/generator.rb', line 20 def clear @examples = [] end |
#result ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/lazy_api_doc/generator.rb', line 24 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 |