Sha256: fa378fca24129dccee68e13097e3d36664540e5906f3e7616ffaa6a802e49d8f

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

module Puppet::ResourceApi
  # A trivial class to provide the functionality required to push data through the existing type/provider parts of puppet
  class TypeShim
    attr_reader :values, :typename, :namevar

    def initialize(title, resource_hash, typename, namevarname)
      # internalize and protect - needs to go deeper
      @values = resource_hash.dup
      # "name" is a privileged key
      @values[namevarname] = title
      @values.freeze

      @typename = typename
      @namevar = namevarname
    end

    def to_resource
      ResourceShim.new(@values, @typename, @namevar)
    end

    def name
      values[@namevar]
    end
  end

  # A trivial class to provide the functionality required to push data through the existing type/provider parts of puppet
  class ResourceShim
    attr_reader :values, :typename, :namevar

    def initialize(resource_hash, typename, namevarname)
      @values = resource_hash.dup.freeze # whatevs
      @typename = typename
      @namevar = namevarname
    end

    def title
      values[@namevar]
    end

    def prune_parameters(*_args)
      # puts "not pruning #{args.inspect}" if args.length > 0
      self
    end

    def to_manifest
      (["#{@typename} { #{values[@namevar].inspect}: "] + values.keys.reject { |k| k == @namevar }.map { |k| "  #{k} => #{Puppet::Parameter.format_value_for_display(values[k])}," } + ['}']).join("\n")
    end

    # Convert our resource to yaml for Hiera purposes.
    def to_hierayaml
      (["  #{values[@namevar]}: "] + values.keys.reject { |k| k == @namevar }.map { |k| "    #{k}: #{Puppet::Parameter.format_value_for_display(values[k])}" }).join("\n") + "\n"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
puppet-resource_api-0.10.0 lib/puppet/resource_api/glue.rb