Class: Puppet::TransObject
- Includes:
- Enumerable
- Defined in:
- lib/vendor/puppet/transportable.rb
Overview
The transportable objects themselves. Basically just a hash with some metadata and a few extra methods. I used to have the object actually be a subclass of Hash, but I could never correctly dump them using YAML.
Instance Attribute Summary collapse
-
#catalog ⇒ Object
Returns the value of attribute catalog.
-
#file ⇒ Object
Returns the value of attribute file.
-
#line ⇒ Object
Returns the value of attribute line.
-
#name ⇒ Object
Returns the value of attribute name.
- #tags ⇒ Object
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(name, type) ⇒ TransObject
constructor
A new instance of TransObject.
- #longname ⇒ Object
- #ref ⇒ Object
-
#to_component ⇒ Object
Convert a defined type into a component.
- #to_hash ⇒ Object
- #to_manifest ⇒ Object
- #to_ral ⇒ Object
- #to_ref ⇒ Object
-
#to_resource ⇒ Object
Create a normalized resource from our TransObject.
- #to_s ⇒ Object
- #to_yaml_properties ⇒ Object
Constructor Details
#initialize(name, type) ⇒ TransObject
Returns a new instance of TransObject.
25 26 27 28 29 30 |
# File 'lib/vendor/puppet/transportable.rb', line 25 def initialize(name,type) @type = type.to_s.downcase @name = name @params = {} @tags = [] end |
Instance Attribute Details
#catalog ⇒ Object
Returns the value of attribute catalog.
11 12 13 |
# File 'lib/vendor/puppet/transportable.rb', line 11 def catalog @catalog end |
#file ⇒ Object
Returns the value of attribute file.
11 12 13 |
# File 'lib/vendor/puppet/transportable.rb', line 11 def file @file end |
#line ⇒ Object
Returns the value of attribute line.
11 12 13 |
# File 'lib/vendor/puppet/transportable.rb', line 11 def line @line end |
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/vendor/puppet/transportable.rb', line 11 def name @name end |
#tags ⇒ Object
41 42 43 |
# File 'lib/vendor/puppet/transportable.rb', line 41 def @tags end |
#type ⇒ Object
Returns the value of attribute type.
11 12 13 |
# File 'lib/vendor/puppet/transportable.rb', line 11 def type @type end |
Instance Method Details
#each ⇒ Object
21 22 23 |
# File 'lib/vendor/puppet/transportable.rb', line 21 def each @params.each { |p,v| yield p, v } end |
#longname ⇒ Object
32 33 34 |
# File 'lib/vendor/puppet/transportable.rb', line 32 def longname [@type,@name].join('--') end |
#ref ⇒ Object
36 37 38 39 |
# File 'lib/vendor/puppet/transportable.rb', line 36 def ref @ref ||= Puppet::Resource.new(@type, @name) @ref.to_s end |
#to_component ⇒ Object
Convert a defined type into a component.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/vendor/puppet/transportable.rb', line 46 def to_component trans = TransObject.new(ref, :component) @params.each { |param,value| next unless Puppet::Type::Component.valid_parameter?(param) Puppet.debug "Defining #{param} on #{ref}" trans[param] = value } trans.catalog = self.catalog Puppet::Type::Component.create(trans) end |
#to_hash ⇒ Object
57 58 59 |
# File 'lib/vendor/puppet/transportable.rb', line 57 def to_hash @params.dup end |
#to_manifest ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/vendor/puppet/transportable.rb', line 65 def to_manifest "%s { '%s':\n%s\n}" % [self.type.to_s, self.name, @params.collect { |p, v| if v.is_a? Array " #{p} => [\'#{v.join("','")}\']" else " #{p} => \'#{v}\'" end }.join(",\n") ] end |
#to_ral ⇒ Object
93 94 95 |
# File 'lib/vendor/puppet/transportable.rb', line 93 def to_ral to_resource.to_ral end |
#to_ref ⇒ Object
89 90 91 |
# File 'lib/vendor/puppet/transportable.rb', line 89 def to_ref ref end |
#to_resource ⇒ Object
Create a normalized resource from our TransObject.
78 79 80 81 82 83 |
# File 'lib/vendor/puppet/transportable.rb', line 78 def to_resource result = Puppet::Resource.new(type, name, :parameters => @params.dup) result.tag(*) result end |
#to_s ⇒ Object
61 62 63 |
# File 'lib/vendor/puppet/transportable.rb', line 61 def to_s "#{@type}(#{@name}) => #{super}" end |
#to_yaml_properties ⇒ Object
85 86 87 |
# File 'lib/vendor/puppet/transportable.rb', line 85 def to_yaml_properties instance_variables.reject { |v| %w{@ref}.include?(v) } end |