Class: LegacyFacter::Util::Parser::Base
- Inherits:
 - 
      Object
      
        
- Object
 - LegacyFacter::Util::Parser::Base
 
 
- Defined in:
 - lib/facter/custom_facts/util/parser.rb
 
Direct Known Subclasses
JsonParser, PowershellParser, ScriptParser, TextParser, YamlParser
Instance Attribute Summary collapse
- 
  
    
      #filename  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute filename.
 
Instance Method Summary collapse
- #content ⇒ Object
 - 
  
    
      #initialize(filename, content = nil)  ⇒ Base 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Base.
 - #log_stderr(msg, command, file) ⇒ Object
 - #parse_executable_output(output) ⇒ Object
 - #parse_results ⇒ Object
 - 
  
    
      #results  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
results on the base class is really meant to be just an exception handler wrapper.
 
Constructor Details
#initialize(filename, content = nil) ⇒ Base
Returns a new instance of Base.
      48 49 50 51  | 
    
      # File 'lib/facter/custom_facts/util/parser.rb', line 48 def initialize(filename, content = nil) @filename = filename @content = content end  | 
  
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
      46 47 48  | 
    
      # File 'lib/facter/custom_facts/util/parser.rb', line 46 def filename @filename end  | 
  
Instance Method Details
#content ⇒ Object
      53 54 55  | 
    
      # File 'lib/facter/custom_facts/util/parser.rb', line 53 def content @content ||= Facter::Util::FileHelper.safe_read(filename, nil) end  | 
  
#log_stderr(msg, command, file) ⇒ Object
      85 86 87 88 89 90 91 92  | 
    
      # File 'lib/facter/custom_facts/util/parser.rb', line 85 def log_stderr(msg, command, file) return if !msg || msg.empty? file_name = file.split('/').last logger = Facter::Log.new(file_name) logger.warn(format(STDERR_MESSAGE, command, msg.strip)) end  | 
  
#parse_executable_output(output) ⇒ Object
      70 71 72 73 74 75 76 77 78 79 80 81 82 83  | 
    
      # File 'lib/facter/custom_facts/util/parser.rb', line 70 def parse_executable_output(output) res = nil begin res = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0') # Ruby 2.6+ YAML.safe_load(output, permitted_classes: [Symbol, Time]) else YAML.safe_load(output, [Symbol, Time]) end rescue StandardError => e Facter.debug("Could not parse executable fact output as YAML or JSON (#{e.})") end res = KeyValuePairOutputFormat.parse output unless res.is_a?(Hash) res end  | 
  
#parse_results ⇒ Object
      66 67 68  | 
    
      # File 'lib/facter/custom_facts/util/parser.rb', line 66 def parse_results raise ArgumentError, 'Subclasses must respond to parse_results' end  | 
  
#results ⇒ Object
results on the base class is really meant to be just an exception handler wrapper.
      59 60 61 62 63 64  | 
    
      # File 'lib/facter/custom_facts/util/parser.rb', line 59 def results parse_results rescue StandardError => e Facter.log_exception(e, "Failed to handle #{filename} as #{self.class} facts: #{e.}") nil end  |