Class: PuppetDocLint::Parser
- Inherits:
-
Object
- Object
- PuppetDocLint::Parser
- Defined in:
- lib/puppet-doc-lint/parser.rb
Instance Method Summary collapse
-
#authors ⇒ Object
def docs.
-
#docs ⇒ Object
Read RDOC contents from parsed object, returns hash of paragraph headings and the following paragraph contents (i.e. parameter and parameter documentation).
-
#initialize(file) ⇒ Parser
constructor
A new instance of Parser.
-
#klass ⇒ Object
Read class from parsed object, returns string containing class.
-
#parameters ⇒ Object
Read parameters from parsed object, returns hash of parameters and default values.
Constructor Details
#initialize(file) ⇒ Parser
Returns a new instance of Parser.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/puppet-doc-lint/parser.rb', line 4 def initialize(file) # Read file and return parsed object pparser = Puppet::Parser::Parser.new(Puppet::Node::Environment.new('production')) if File.exists?(file) @file = File.(file) pparser.import(@file) # Find object in list of hostclasses pparser.environment.known_resource_types.hostclasses.each do |x| @object = x.last if x.last.file == @file end # Find object in list of definitions pparser.environment.known_resource_types.definitions.each do |x| @object = x.last if x.last.file == @file end else 'File does not exist' end end |
Instance Method Details
#authors ⇒ Object
def docs
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/puppet-doc-lint/parser.rb', line 58 def if !@object.doc.nil? rdoc = RDoc::Markup.parse(@object.doc) = [] = rdoc.parts.chunk{|i|i.class == RDoc::Markup::Heading && i.text == 'Authors'}.reject{|sep,ans| sep}.map{|sep,ans| ans} .each do | doc_chunk | unless doc_chunk[1].class == RDoc::Markup::BlankLine || doc_chunk[1].class == RDoc::Markup::Heading || !doc_chunk[1].respond_to?(:items) doc_chunk[1].items.each do |chunk| << chunk.parts.first.parts end end end end # if nil? end |
#docs ⇒ Object
Read RDOC contents from parsed object, returns hash of paragraph headings and the following paragraph contents (i.e. parameter and parameter documentation)
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/puppet-doc-lint/parser.rb', line 40 def docs if !@object.doc.nil? rdoc = RDoc::Markup.parse(@object.doc) docs = {} rdoc.parts.each do |part| if part.respond_to?(:items) part.items.each do |item| next if item.label.nil? || item.parts.first.class == RDoc::Markup::BlankLine key = item.label.to_s.tr('^A-Za-z0-9_-', '') docs[key] = item.parts.first.parts end # do item end # endif end # do parm docs end # if nil? end |
#klass ⇒ Object
Read class from parsed object, returns string containing class
33 34 35 |
# File 'lib/puppet-doc-lint/parser.rb', line 33 def klass @object.name if (defined? @object.class.name) end |
#parameters ⇒ Object
Read parameters from parsed object, returns hash of parameters and default values
27 28 29 30 |
# File 'lib/puppet-doc-lint/parser.rb', line 27 def parameters result = (defined? @object.arguments) ? @object.arguments : {} result end |