class RspecApiDocumentation::Writers::JSONIndex

Public Class Methods

new(index, configuration) click to toggle source
# File lib/rspec_api_documentation/writers/json_writer.rb, line 31
def initialize(index, configuration)
  @index = index
  @configuration = configuration
end

Public Instance Methods

as_json(opts = nil) click to toggle source
# 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
examples() click to toggle source
# 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) click to toggle source
# 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.metadata[:document],
        :route => example.route,
        :method => example.metadata[:method]
      }
    }
  }
end
sections() click to toggle source
# File lib/rspec_api_documentation/writers/json_writer.rb, line 36
def sections
  IndexHelper.sections(examples, @configuration)
end