class PackerFiles::DocGenerator
Public Class Methods
new(class_name, filename)
click to toggle source
Constructor accepts a class name and the file name to write the documentation to.
# File lib/PackerFiles/OS/DocGenerator.rb, line 10 def initialize(class_name, filename) @class_name = class_name @file_name = filename end
Public Instance Methods
Generate()
click to toggle source
Generate
the documentation.This is done by looking at the type accessors that are defined by the OS class and then calling the doc_file function to figure out the ERB template.
# File lib/PackerFiles/OS/DocGenerator.rb, line 18 def Generate # Generate content for all the type accessor classes. content = [] ancestry_class_list.each do |class_name| hash = class_name.type_accessors next if hash.nil? hash.each_pair { |func, type_data| file = type_data.first.doc_file hash = {'name' => func, 'mod' => PackerFiles} doc = PackerFiles.evaluate_erb(file, hash) content += doc.split("\n").map {|line| ' ' + line } } end # Generate content for the top level structure. top_doc_file = PackerFiles.DirPath('OS/example/Doc.txt').first os_name = @class_name.name.gsub('PackerFiles::', '') hash = Hash['os_name', os_name, 'content', content] value = PackerFiles.evaluate_erb(top_doc_file, hash) File.write(@file_name, value) end
Private Instance Methods
ancestry_class_list()
click to toggle source
Get the complete hierarchy of classes until PackerFiles::Builder
. This is to ensure that all type_accessors are captured at every inheritance level.
# File lib/PackerFiles/OS/DocGenerator.rb, line 45 def ancestry_class_list index = @class_name.ancestors.index(PackerFiles::Builder) @class_name.ancestors.slice(0, index + 1) end