Class: DevStructure::Puppet::Manifest
- Inherits:
-
Object
- Object
- DevStructure::Puppet::Manifest
- Defined in:
- lib/devstructure/puppet.rb
Overview
A Puppet manifest that contains a tree of classes that each contain some resources.
Instance Method Summary collapse
-
#<<(resource) ⇒ Object
Add a resource to this manifest.
-
#[](name) ⇒ Object
Return a reference to a sub-manifest of the given name.
-
#initialize(name, parent = nil) ⇒ Manifest
constructor
A new instance of Manifest.
- #method_missing(symbol, *args) ⇒ Object
- #to_s(tab = "") ⇒ Object
Constructor Details
#initialize(name, parent = nil) ⇒ Manifest
Returns a new instance of Manifest.
16 17 18 19 |
# File 'lib/devstructure/puppet.rb', line 16 def initialize(name, parent=nil) @name, @parent = name, parent @manifests, @resources = {}, {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
25 26 27 |
# File 'lib/devstructure/puppet.rb', line 25 def method_missing(symbol, *args) self[symbol] end |
Instance Method Details
#<<(resource) ⇒ Object
Add a resource to this manifest.
30 31 32 33 |
# File 'lib/devstructure/puppet.rb', line 30 def <<(resource) @resources[resource.type] ||= [] @resources[resource.type] << resource end |
#[](name) ⇒ Object
Return a reference to a sub-manifest of the given name.
22 23 24 |
# File 'lib/devstructure/puppet.rb', line 22 def [](name) @manifests[name.to_s] ||= self.class.new(name.to_s, @name) end |
#to_s(tab = "") ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/devstructure/puppet.rb', line 35 def to_s(tab="") out = [] out << "#{tab}class #{@name.gsub(".", "--")} {" @manifests.each_value do |manifest| out << manifest.to_s("#{tab}\t") end @resources.each do |type, resources| if 1 < resources.length out << "#{tab}\t#{type} {" resources.each do |resource| resource.style = :partial out << resource.to_s("#{tab}\t") end out << "#{tab}\t}" else out << resources.first.to_s("#{tab}\t") end end out << "#{tab}}" out << "#{tab}include #{@name.gsub(".", "--")}" if @parent out.join("\n") end |