Class: RspecApiDocumentation::Writers::JsonIndex

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

Direct Known Subclasses

AppendJsonIndex

Instance Method Summary collapse

Constructor Details

#initialize(index, configuration) ⇒ JsonIndex

Returns a new instance of JsonIndex.



25
26
27
28
# File 'lib/rspec_api_documentation/writers/json_iodocs_writer.rb', line 25

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

Instance Method Details

#as_json(opts = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rspec_api_documentation/writers/json_iodocs_writer.rb', line 38

def as_json(opts = nil)
  sections.inject({:endpoints => []}) do |h, section|
    h[:endpoints].push(
      :name => section[:resource_name],
      :methods => section[:examples].map do |example|
        example.as_json(opts)
      end
    )
    h
  end
end

#examplesObject



34
35
36
# File 'lib/rspec_api_documentation/writers/json_iodocs_writer.rb', line 34

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

#sectionsObject



30
31
32
# File 'lib/rspec_api_documentation/writers/json_iodocs_writer.rb', line 30

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