Sha256: 14bc6915952ae48a7887de7221859323c719b86daaec25063628768cec1366c2

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

Stored size: 1.09 KB

Contents

require_relative '../facts'
require 'yaml'

module OctocatalogDiff
  class Facts
    # Deal with facts in YAML files
    class Yaml
      # Manipulate a YAML file so it can be parsed and return the facts as a hash.
      # If we leave it as Puppet::Node::Facts then it will require us to load puppet
      # gems in order to parse it, and that's too heavy for simple fact retrieval.
      # @param options [Hash] Options hash specifically for this fact type.
      #          - :fact_file_string [String] => Fact data as a string
      # @param node [String] Node name (overrides node name from fact data)
      # @return [Hash] Facts
      def self.fact_retriever(options = {}, node = '')
        fact_file_string = options.fetch(:fact_file_string)

        # Touch up the first line before parsing.
        fact_file_data = fact_file_string.split(/\n/)
        fact_file_data[0] = '---' if fact_file_data[0] =~ /^---/

        # Load and return the parsed fact file.
        result = YAML.load(fact_file_data.join("\n"))
        result['name'] = node unless node == ''
        result
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
octocatalog-diff-0.5.6 lib/octocatalog-diff/facts/yaml.rb
octocatalog-diff-0.5.4 lib/octocatalog-diff/facts/yaml.rb
octocatalog-diff-0.5.3 lib/octocatalog-diff/facts/yaml.rb
octocatalog-diff-0.5.1 lib/octocatalog-diff/facts/yaml.rb