class GhostWriter::Document
Attributes
basename[R]
description[R]
header[RW]
location[R]
param_example[R]
path_info[R]
relative_path[R]
request_method[R]
response_format[R]
status_code[R]
title[R]
Public Class Methods
new(basename, attrs)
click to toggle source
# File lib/ghost_writer/document.rb, line 7 def initialize(basename, attrs) @basename = basename @relative_path = basename @title = attrs[:title] @description = attrs[:description] @location = attrs[:location] @request_method = attrs[:request_method] @path_info = attrs[:path_info] param_example = attrs[:param_example].stringify_keys @response_format = param_example.delete("format").to_s @param_example = param_example @status_code = attrs[:status_code] @response_body = attrs[:response_body] end
Public Instance Methods
content_type()
click to toggle source
# File lib/ghost_writer/document.rb, line 47 def content_type if response_format == "json" "application/json; charset=UTF-8" else "text/html; charset=UTF-8" end end
response_body()
click to toggle source
# File lib/ghost_writer/document.rb, line 35 def response_body arrange_json(@response_body) end
serialized_params()
click to toggle source
# File lib/ghost_writer/document.rb, line 28 def serialized_params Oj.dump(param_example) rescue NoMemoryError, StandardError puts "Param serialize error: #{param_example.inspect} of #{description} at #{location}" param_example.inspect end
write_file(options = {})
click to toggle source
# File lib/ghost_writer/document.rb, line 23 def write_file(options = {}) writer = GhostWriter::Writer.new(self, options) writer.write_file end
Private Instance Methods
arrange_json(body)
click to toggle source
# File lib/ghost_writer/document.rb, line 57 def arrange_json(body) return body unless response_format == "json" data = Oj.load(body) if data.is_a?(Array) || data.is_a?(Hash) JSON.pretty_generate(data) else data end rescue Oj::Error body end