Class: RspecApiDocumentation::Writers::JsonIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_api_documentation/writers/json_writer.rb,
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.



27
28
29
30
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 27

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

Instance Method Details

#as_json(opts = nil) ⇒ Object



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

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

#examplesObject



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

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

#section_hash(section) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 47

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

#sectionsObject



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

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