Class: RspecApiDocumentation::Writers::JSONIndex
- Inherits:
-
Object
- Object
- RspecApiDocumentation::Writers::JSONIndex
- Defined in:
- lib/rspec_api_documentation/writers/json_writer.rb
Instance Method Summary collapse
- #as_json(opts = nil) ⇒ Object
- #examples ⇒ Object
-
#initialize(index, configuration) ⇒ JSONIndex
constructor
A new instance of JSONIndex.
- #section_hash(section) ⇒ Object
- #sections ⇒ Object
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 |
#examples ⇒ Object
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 |
#sections ⇒ Object
36 37 38 |
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 36 def sections IndexHelper.sections(examples, @configuration) end |