Class: OctocatalogDiff::CatalogUtil::Facts

Inherits:
Object
  • Object
show all
Defined in:
lib/octocatalog-diff/catalog-util/facts.rb

Overview

Helper class to construct a fact object based on options provided by cli/options. Supports a direct fact file, looking up a YAML file based on node name within Puppet fact directories, or retrieving from PuppetDB.

Instance Method Summary collapse

Constructor Details

#initialize(options, logger = nil) ⇒ Facts

Constructor

Parameters:

  • options (Hash)

    Options from cli/options

  • logger (Logger) (defaults to: nil)

    Logger object for debug messages (optional)

Raises:

  • (ArgumentError)

14
15
16
17
18
19
20
21
22
# File 'lib/octocatalog-diff/catalog-util/facts.rb', line 14

def initialize(options, logger = nil)
  raise ArgumentError, "Argument to constructor must be Hash not #{options.class}" unless options.is_a?(Hash)
  @options = options.dup
  @logger = logger

  # Environment variable recognition
  @options[:puppetdb_url] ||= ENV['PUPPETDB_URL'] if ENV['PUPPETDB_URL']
  @options[:puppet_fact_dir] ||= ENV['PUPPET_FACT_DIR'] if ENV['PUPPET_FACT_DIR']
end

Instance Method Details

#factsHash

Compute facts if needed and then return them

Returns:

  • (Hash)

    Facts


26
27
28
# File 'lib/octocatalog-diff/catalog-util/facts.rb', line 26

def facts
  @facts ||= compute_facts
end