Method: RDoc::PuppetParserCore#parse_fact

Defined in:
lib/puppet/util/rdoc/parser/puppet_parser_core.rb

#parse_fact(container) ⇒ Object

this is a poor man custom fact parser :-)



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/puppet/util/rdoc/parser/puppet_parser_core.rb', line 149

def parse_fact(container)
  comments = ""
  current_fact = nil
  parsed_facts = []
  File.open(@input_file_name) do |of|
    of.each do |line|
      # fetch comments
      case line
      when /^[ \t]*# ?(.*)$/
        comments += ::Regexp.last_match(1) + "\n"
      when /^[ \t]*(Facter.add|Puppet\.runtime\[:facter\].add)\(['"](.*?)['"]\)/
        current_fact = RDoc::Fact.new(::Regexp.last_match(1), {})
        look_for_directives_in(container, comments) unless comments.empty?
        current_fact.comment = comments
        parsed_facts << current_fact
        comments = ""
        Puppet.debug "rdoc: found custom fact #{current_fact.name}"
      when /^[ \t]*confine[ \t]*:(.*?)[ \t]*=>[ \t]*(.*)$/
        current_fact.confine = { :type => ::Regexp.last_match(1), :value => ::Regexp.last_match(2) } unless current_fact.nil?
      else # unknown line type
        comments = ""
      end
    end
  end
  parsed_facts.each do |f|
    container.add_fact(f)
    f.record_location(@top_level)
  end
end