Class: RspecApiDocumentation::Writers::JsonIndex
- Inherits:
-
Object
- Object
- RspecApiDocumentation::Writers::JsonIndex
- Defined in:
- lib/rspec_api_documentation/writers/json_writer.rb,
lib/rspec_api_documentation/writers/json_iodocs_writer.rb
Direct Known Subclasses
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.
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 |
#examples ⇒ Object
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 |
#sections ⇒ Object
32 33 34 |
# File 'lib/rspec_api_documentation/writers/json_writer.rb', line 32 def sections IndexHelper.sections(examples, @configuration) end |