Class: Puppet::ResourceApi::ResourceShim
- Inherits:
-
Object
- Object
- Puppet::ResourceApi::ResourceShim
- 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
-
#attr_def ⇒ Object
readonly
Returns the value of attribute attr_def.
-
#namevar ⇒ Object
readonly
Returns the value of attribute namevar.
-
#typename ⇒ Object
readonly
Returns the value of attribute typename.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
-
#initialize(resource_hash, typename, namevarname, attr_def) ⇒ ResourceShim
constructor
A new instance of ResourceShim.
- #prune_parameters(*_args) ⇒ Object
- #title ⇒ Object
-
#to_hierayaml ⇒ Object
Convert our resource to yaml for Hiera purposes.
- #to_manifest ⇒ Object
Constructor Details
#initialize(resource_hash, typename, namevarname, attr_def) ⇒ ResourceShim
Returns a new instance of ResourceShim.
32 33 34 35 36 37 |
# File 'lib/puppet/resource_api/glue.rb', line 32 def initialize(resource_hash, typename, namevarname, attr_def) @values = resource_hash.dup.freeze # whatevs @typename = typename @namevar = namevarname @attr_def = attr_def end |
Instance Attribute Details
#attr_def ⇒ Object (readonly)
Returns the value of attribute attr_def.
30 31 32 |
# File 'lib/puppet/resource_api/glue.rb', line 30 def attr_def @attr_def end |
#namevar ⇒ Object (readonly)
Returns the value of attribute namevar.
30 31 32 |
# File 'lib/puppet/resource_api/glue.rb', line 30 def namevar @namevar end |
#typename ⇒ Object (readonly)
Returns the value of attribute typename.
30 31 32 |
# File 'lib/puppet/resource_api/glue.rb', line 30 def typename @typename end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
30 31 32 |
# File 'lib/puppet/resource_api/glue.rb', line 30 def values @values end |
Instance Method Details
#prune_parameters(*_args) ⇒ Object
43 44 45 46 |
# File 'lib/puppet/resource_api/glue.rb', line 43 def prune_parameters(*_args) # puts "not pruning #{args.inspect}" if args.length > 0 self end |
#title ⇒ Object
39 40 41 |
# File 'lib/puppet/resource_api/glue.rb', line 39 def title values[@namevar] end |
#to_hierayaml ⇒ Object
Convert our resource to yaml for Hiera purposes.
61 62 63 |
# File 'lib/puppet/resource_api/glue.rb', line 61 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 |
#to_manifest ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/puppet/resource_api/glue.rb', line 48 def to_manifest (["#{@typename} { #{values[@namevar].inspect}: "] + values.keys.reject { |k| k == @namevar }.map do |k| cs = ' ' ce = '' if attr_def[k][:behaviour] && attr_def[k][:behaviour] == :read_only cs = '#' ce = ' # Read Only' end "#{cs} #{k} => #{Puppet::Parameter.format_value_for_display(values[k])},#{ce}" end + ['}']).join("\n") end |