Module: LegacyFacter::Util::Parser

Defined in:
lib/facter/custom_facts/util/parser.rb

Defined Under Namespace

Modules: KeyValuePairOutputFormat Classes: Base, JsonParser, NothingParser, PowershellParser, ScriptParser, TextParser, YamlParser

Constant Summary collapse

STDERR_MESSAGE =
'Command %s completed with the following stderr message: %s'
TIME =

This regex was taken from Psych and adapted github.com/ruby/psych/blob/d2deaa9adfc88fc0b870df022a434d6431277d08/lib/psych/scalar_scanner.rb#L9 It is used to detect Time in YAML, but we use it to wrap time objects in quotes to be treated as strings.

/(\d{4}-\d{1,2}-\d{1,2}(?:[Tt]|\s+)\d{1,2}:\d\d:\d\d(?:\.\d*)?(?:\s*(?:Z|[-+]\d{1,2}:?(?:\d\d)?))?\s*$)/.freeze

Class Method Summary collapse

Class Method Details

.extension_matches?(filename, ext) ⇒ Boolean

For support mutliple extensions you can pass an array of extensions as ext.

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
# File 'lib/facter/custom_facts/util/parser.rb', line 17

def self.extension_matches?(filename, ext)
  extension = case ext
              when String
                ext.downcase
              when Enumerable
                ext.collect(&:downcase)
              end
  [extension].flatten.to_a.include?(file_extension(filename).downcase)
end

.file_extension(filename) ⇒ Object



27
28
29
# File 'lib/facter/custom_facts/util/parser.rb', line 27

def self.file_extension(filename)
  File.extname(filename).sub('.', '')
end

.parser_for(filename) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/facter/custom_facts/util/parser.rb', line 35

def self.parser_for(filename)
  registration = @parsers.detect { |k| k[1].call(filename) }

  if registration.nil?
    NothingParser.new
  else
    registration[0].new(filename)
  end
end

.register(klass, &suitable) ⇒ Object



31
32
33
# File 'lib/facter/custom_facts/util/parser.rb', line 31

def self.register(klass, &suitable)
  @parsers << [klass, suitable]
end