Class: GrapeDoc::DOCGenerator
- Inherits:
-
Object
- Object
- GrapeDoc::DOCGenerator
- Defined in:
- lib/grape_doc/doc_generator.rb
Instance Attribute Summary collapse
-
#formatter ⇒ Object
Returns the value of attribute formatter.
-
#resources ⇒ Object
Returns the value of attribute resources.
-
#single_file ⇒ Object
Returns the value of attribute single_file.
Instance Method Summary collapse
- #generate ⇒ Object
- #init_formatter ⇒ Object
-
#initialize(resource_path) ⇒ DOCGenerator
constructor
A new instance of DOCGenerator.
- #load ⇒ Object
Constructor Details
#initialize(resource_path) ⇒ DOCGenerator
Returns a new instance of DOCGenerator.
6 7 8 9 10 11 12 13 |
# File 'lib/grape_doc/doc_generator.rb', line 6 def initialize(resource_path) begin require resource_path self.load rescue LoadError => ex puts "#{ex}" end end |
Instance Attribute Details
#formatter ⇒ Object
Returns the value of attribute formatter.
3 4 5 |
# File 'lib/grape_doc/doc_generator.rb', line 3 def formatter @formatter end |
#resources ⇒ Object
Returns the value of attribute resources.
3 4 5 |
# File 'lib/grape_doc/doc_generator.rb', line 3 def resources @resources end |
#single_file ⇒ Object
Returns the value of attribute single_file.
3 4 5 |
# File 'lib/grape_doc/doc_generator.rb', line 3 def single_file @single_file end |
Instance Method Details
#generate ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/grape_doc/doc_generator.rb', line 30 def generate doc_formatter = init_formatter doc_dir = "#{Dir.pwd}/grape_doc" FileUtils.mkdir_p(doc_dir) self.resources.each do | resource | File.open(File.join(doc_dir, "#{resource.resource_name}.md"), 'w') {|f| f.write doc_formatter.generate_resource_doc(resource) } end end |
#init_formatter ⇒ Object
15 16 17 |
# File 'lib/grape_doc/doc_generator.rb', line 15 def init_formatter return GrapeDoc::MarkdownFormatter.new if self.formatter.nil? end |
#load ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/grape_doc/doc_generator.rb', line 19 def load self.resources = Grape::API.subclasses.map do |klass| resource = APIResource.new(klass) if resource.documents.nil? or resource.documents.count.zero? nil else resource end end.compact.sort_by{ |res| res.resource_name } end |