Class: GrapeDocumenter::Generator
- Inherits:
-
Object
- Object
- GrapeDocumenter::Generator
- Defined in:
- lib/grape_documenter/generator.rb
Overview
Generator
Instance Attribute Summary collapse
-
#mounted_path ⇒ Object
readonly
Returns the value of attribute mounted_path.
Instance Method Summary collapse
- #generate_namespace_docs ⇒ Object
-
#initialize(api_class, output_path, options = {}) ⇒ Generator
constructor
A new instance of Generator.
- #output ⇒ Object
Constructor Details
#initialize(api_class, output_path, options = {}) ⇒ Generator
Returns a new instance of Generator.
9 10 11 12 13 14 15 16 17 |
# File 'lib/grape_documenter/generator.rb', line 9 def initialize(api_class, output_path, = {}) raise 'api_class must be specified' if api_class.nil? raise 'output_path must be specified' if output_path.nil? @output_path = output_path @api_class = api_class.constantize @format = [:format] || 'html' @mounted_path = [:mounted_path] || '' end |
Instance Attribute Details
#mounted_path ⇒ Object (readonly)
Returns the value of attribute mounted_path.
7 8 9 |
# File 'lib/grape_documenter/generator.rb', line 7 def mounted_path @mounted_path end |
Instance Method Details
#generate_namespace_docs ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/grape_documenter/generator.rb', line 19 def generate_namespace_docs docs = [] @api_class.versions.each do |version| namespaces_for_version(version).each do |namespace| docs << NamespaceDoc.new(:version => version, :title => titleize(namespace), :root_path => namespace, :routes => routes_for_version_and_namespace(version, namespace), :resources => resources_for_version(version)) end end docs end |
#output ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/grape_documenter/generator.rb', line 35 def output files = {} generate_namespace_docs.each do |doc| puts doc.title filename = File.join(@output_path, doc.version, "#{doc.root_path}.#{@format}") files[filename] = self.send("generate_#{@format}", doc) end Writer.new(files).write_to_files! end |