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.



9
10
11
# File 'lib/lazy_api_doc/generator.rb', line 9

def initialize
  @examples = []
end

Instance Attribute Details

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

#clearObject



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

def clear
  @examples = []
end

#resultObject



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