Class: Puppet::ResourceApi::ResourceShim

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/resource_api/glue.rb

Overview

A trivial class to provide the functionality required to push data through the existing type/provider parts of puppet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_hash, typename) ⇒ ResourceShim

Returns a new instance of ResourceShim.



29
30
31
32
# File 'lib/puppet/resource_api/glue.rb', line 29

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

Instance Attribute Details

#typenameObject (readonly)

Returns the value of attribute typename.



27
28
29
# File 'lib/puppet/resource_api/glue.rb', line 27

def typename
  @typename
end

#valuesObject (readonly)

Returns the value of attribute values.



27
28
29
# File 'lib/puppet/resource_api/glue.rb', line 27

def values
  @values
end

Instance Method Details

#prune_parameters(*_args) ⇒ Object



38
39
40
41
# File 'lib/puppet/resource_api/glue.rb', line 38

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

#titleObject



34
35
36
# File 'lib/puppet/resource_api/glue.rb', line 34

def title
  values[:name]
end

#to_hierayamlObject

Convert our resource to yaml for Hiera purposes.



48
49
50
# File 'lib/puppet/resource_api/glue.rb', line 48

def to_hierayaml
  (["  #{values[:name]}: "] + values.keys.reject { |k| k == :name }.map { |k| "    #{k}: #{Puppet::Parameter.format_value_for_display(values[k])}" }).join("\n") + "\n"
end

#to_manifestObject



43
44
45
# File 'lib/puppet/resource_api/glue.rb', line 43

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