Class: RspecApiDocumentation::Writers::JSONIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_api_documentation/writers/json_writer.rb

Instance Method Summary collapse

Constructor Details

#initialize(index, configuration) ⇒ JSONIndex

Returns a new instance of JSONIndex.



31
32
33
34
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 31

def initialize(index, configuration)
  @index = index
  @configuration = configuration
end

Instance Method Details

#as_json(opts = nil) ⇒ Object



44
45
46
47
48
49
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 44

def as_json(opts = nil)
  sections.inject({:resources => []}) do |h, section|
    h[:resources].push(section_hash(section))
    h
  end
end

#examplesObject



40
41
42
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 40

def examples
  @index.examples.map { |example| JSONExample.new(example, @configuration) }
end

#section_hash(section) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 51

def section_hash(section)
  {
    :name => section[:resource_name],
    :explanation => section[:resource_explanation],
    :examples => section[:examples].map { |example|
      {
        :description => example.description,
        :link => "#{example.dirname}/#{example.filename}",
        :groups => example.[:document],
        :route => example.route,
        :method => example.[:method]
      }
    }
  }
end

#sectionsObject



36
37
38
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 36

def sections
  IndexHelper.sections(examples, @configuration)
end