module GhostWriter
Constants
- DEFAULT_FORMAT
- DEFAULT_OUTPUT_DIR
- DOCUMENT_INDEX_FILENAME
- VERSION
Attributes
github_base_url[RW]
output_dir[W]
output_flag[W]
output_format[W]
Public Class Methods
document_group()
click to toggle source
# File lib/ghost_writer.rb, line 25 def document_group @document_group ||= {} @document_group end
generate_api_doc()
click to toggle source
# File lib/ghost_writer.rb, line 30 def generate_api_doc if output_flag unless File.exist?(output_dir) FileUtils.mkdir_p(output_dir) end document_index = GhostWriter::DocumentIndex.new(output_dir + "#{DOCUMENT_INDEX_FILENAME}", document_group, GhostWriter.output_format) document_index.write_file(format: output_format) document_group.each do |output, docs| docs.sort_by!(&:location) initial = docs.shift initial.header = true initial.write_file(format: output_format, overwrite: true) docs.each {|d| d.write_file(format: output_format) } end document_group.clear end end
output_dir()
click to toggle source
# File lib/ghost_writer.rb, line 53 def output_dir @output_dir ? Pathname(@output_dir) : Pathname(DEFAULT_OUTPUT_DIR) end
output_flag()
click to toggle source
# File lib/ghost_writer.rb, line 49 def output_flag !!(@output_flag ? @output_flag : ENV["GENERATE_API_DOC"]) end
output_format()
click to toggle source
# File lib/ghost_writer.rb, line 57 def output_format @output_format || DEFAULT_FORMAT end
Public Instance Methods
collect_example(example)
click to toggle source
# File lib/ghost_writer.rb, line 62 def collect_example(example) output = doc_dir + doc_name(example) document = GhostWriter::Document.new(output, { title: "#{described_class} #{doc_name(example).titleize}", description: example.full_description.dup, location: example.location.dup, request_method: request.env["REQUEST_METHOD"], path_info: request.env["PATH_INFO"], param_example: controller.params.reject {|key, val| key == "controller" || key == "action"}, status_code: response.status, response_body: response.body, format: GhostWriter.output_format }) GhostWriter.document_group[output] ||= [] GhostWriter.document_group[output] << document end
Private Instance Methods
doc_dir()
click to toggle source
# File lib/ghost_writer.rb, line 81 def doc_dir GhostWriter.output_dir + described_class.to_s.underscore end
doc_name(example)
click to toggle source
# File lib/ghost_writer.rb, line 85 def doc_name(example) metadata = example.metadata[:generate_api_doc] || example.metadata[:ghost_writer] case metadata when String, Symbol example.metadata[:generate_api_doc].to_s else controller.action_name end end