class RspecApiDocumentation::Writers::AppendJsonIndex

Public Class Methods

new(index, configuration, existing_index_hash = nil) click to toggle source
# File lib/rspec_api_documentation/writers/append_json_writer.rb, line 23
def initialize(index, configuration, existing_index_hash = nil)
  @index = index
  @configuration = configuration
  @existing_index_hash = clean_index_hash(existing_index_hash)
end

Public Instance Methods

as_json(opts = nil) click to toggle source
# File lib/rspec_api_documentation/writers/append_json_writer.rb, line 29
def as_json(opts = nil)
  sections.inject(@existing_index_hash) do |h, section|
    h[:resources].push(section_hash(section))
    h
  end
end
clean_index_hash(existing_index_hash) click to toggle source
# File lib/rspec_api_documentation/writers/append_json_writer.rb, line 36
def clean_index_hash(existing_index_hash)
  unless existing_index_hash.is_a?(Hash) && existing_index_hash["resources"].is_a?(Array) #check format
    existing_index_hash = {:resources => []}
  end
  existing_index_hash = existing_index_hash.deep_symbolize_keys
  existing_index_hash[:resources].map!(&:deep_symbolize_keys).reject! do |resource|
    resource_names = sections.map{|s| s[:resource_name]}
    resource_names.include? resource[:name]
  end
  existing_index_hash
end