Class: LazyApiDoc::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/lazy_api_doc/generator.rb

Constant Summary collapse

EXCLUDED_PARAMS =
["controller", "action", "format"].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGenerator

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

#examplesObject (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

#clearObject



20
21
22
# File 'lib/lazy_api_doc/generator.rb', line 20

def clear
  @examples = []
end

#resultObject



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