class RspecApiDocs::Renderer::JSONRenderer
Attributes
resources[R]
Public Class Methods
new(resources)
click to toggle source
# File lib/rspec_api_docs/formatter/renderer/json_renderer.rb, line 10 def initialize(resources) @resources = resources end
Public Instance Methods
render()
click to toggle source
# File lib/rspec_api_docs/formatter/renderer/json_renderer.rb, line 14 def render FileUtils.mkdir_p output_file.dirname File.open(output_file, 'w') do |f| f.write JSON.pretty_generate(output) + "\n" end end
Private Instance Methods
lower_camel_case(string)
click to toggle source
# File lib/rspec_api_docs/formatter/renderer/json_renderer.rb, line 48 def lower_camel_case(string) string = string.split('_').collect(&:capitalize).join string[0].downcase + string[1..-1] end
output()
click to toggle source
# File lib/rspec_api_docs/formatter/renderer/json_renderer.rb, line 24 def output resources.map do |resource| recursive_format_hash ResourceSerializer.new(resource).to_h end end
output_file()
click to toggle source
# File lib/rspec_api_docs/formatter/renderer/json_renderer.rb, line 53 def output_file Pathname.new(RspecApiDocs.configuration.output_dir) + 'index.json' end
recursive_format_hash(hash)
click to toggle source
# File lib/rspec_api_docs/formatter/renderer/json_renderer.rb, line 30 def recursive_format_hash(hash) case hash when Hash Hash[ hash.map do |key, v| [ key.is_a?(Symbol) && key =~ /\A[a-z]/ ? lower_camel_case(key.to_s).to_sym : key, recursive_format_hash(v), ] end ] when Enumerable hash.map { |value| recursive_format_hash(value) } else hash end end