Class Puppet::DSL::Aspect
In: lib/puppet/dsl.rb
Parent: Object

Methods

[]   []=   child_of?   clear   delete   each   evaluate   evaluated?   export   new   newresource   scope   type  

Included Modules

Puppet::Util Puppet::DSL

Constants

Resource = Puppet::Parser::Resource

Attributes

evaluated  [RW] 
name  [RW] 
parent  [RW] 

Public Class methods

[Source]

     # File lib/puppet/dsl.rb, line 129
129:         def self.[](name)
130:             name = symbolize(name)
131: 
132:             # Make sure there's always a main.  This can get deleted in testing.
133:             if name == :main and ! @aspects[name]
134:                 new(:main) {}
135:             end
136:             @aspects[name]
137:         end

[Source]

     # File lib/puppet/dsl.rb, line 124
124:         def self.[]=(name, aspect)
125:             name = symbolize(name)
126:             @aspects[name] = aspect
127:         end

[Source]

     # File lib/puppet/dsl.rb, line 139
139:         def self.clear
140:             @aspects.clear
141:             @@objects.clear
142:         end

[Source]

     # File lib/puppet/dsl.rb, line 144
144:         def self.delete(name)
145:             name = symbolize(name)
146:             if @aspects.has_key?(name)
147:                 @aspects.delete(name)
148:             end
149:         end

[Source]

     # File lib/puppet/dsl.rb, line 151
151:         def self.each
152:             @aspects.each do |name, a|
153:                 yield name, a
154:             end
155:         end

[Source]

     # File lib/puppet/dsl.rb, line 203
203:         def initialize(name, options = {}, &block)
204:             name = symbolize(name)
205:             @name = name
206:             if block
207:                 @block = block
208:             end
209:             if pname = options[:inherits]
210:                 if pname.is_a?(self.class)
211:                     @parent = pname
212:                 elsif parent = self.class[pname]
213:                     @parent = parent
214:                 else
215:                     raise "Could not find parent aspect %s" % pname
216:                 end
217:             end
218: 
219:             @resources = []
220: 
221:             self.class[name] = self
222:         end

Public Instance methods

[Source]

     # File lib/puppet/dsl.rb, line 157
157:         def child_of?(aspect)
158:             unless aspect.is_a?(self.class)
159:                 obj = self.class[aspect]
160:                 unless obj
161:                     raise "Could not find aspect %s" % aspect
162:                 end
163:                 aspect = obj
164:             end
165:             if self.parent
166:                 if self.parent == aspect
167:                     return true
168:                 elsif self.parent.child_of?(aspect)
169:                     return true
170:                 else
171:                     return false
172:                 end
173:             else
174:                 return false
175:             end
176:         end

[Source]

     # File lib/puppet/dsl.rb, line 178
178:         def evaluate
179:             if self.parent and ! self.parent.evaluated?
180:                 self.parent.evaluate
181:             end
182: 
183:             unless evaluated?
184:                 if defined? @block
185:                     instance_eval(&@block)
186:                 end
187:                 @evaluated = true
188:             end
189:         end

[Source]

     # File lib/puppet/dsl.rb, line 191
191:         def evaluated?
192:             if self.evaluated
193:                 true
194:             else
195:                 false
196:             end
197:         end

[Source]

     # File lib/puppet/dsl.rb, line 199
199:         def export
200:             @resources.dup
201:         end

[Source]

     # File lib/puppet/dsl.rb, line 224
224:         def newresource(type, name, params = {})
225:             if self.is_a?(Puppet::DSL::Aspect)
226:                 source = self
227:             else
228:                 source = Puppet::DSL::Aspect[:main]
229:             end
230:             unless obj = @@objects[type][name]
231:                 obj = Resource.new :title => name, :type => type.name,
232:                     :source => source, :scope => scope
233:                 @@objects[type][name] = obj
234: 
235:                 @resources << obj
236:             end
237: 
238:             params.each do |name, value|
239:                 param = Resource::Param.new(
240:                     :name => name,
241:                     :value => value,
242:                     :source => source
243:                 )
244: 
245:                 obj.send(:set_parameter, param)
246:             end
247: 
248:             obj
249:         end

[Source]

     # File lib/puppet/dsl.rb, line 251
251:         def scope
252:             unless defined?(@scope)
253:                 # Set the code to something innocuous; we just need the
254:                 # scopes, not the interpreter.  Hackish, but true.
255:                 Puppet[:code] = " "
256:                 @interp = Puppet::Parser::Interpreter.new
257:                 require 'puppet/node'
258:                 @node = Puppet::Node.new(Facter.value(:hostname))
259:                 if env = Puppet[:environment] and env == ""
260:                     env = nil
261:                 end
262:                 @node.parameters = Facter.to_hash
263:                 @compile = Puppet::Parser::Compiler.new(@node, @interp.send(:parser, env))
264:                 @scope = @compile.topscope
265:             end
266:             @scope
267:         end

[Source]

     # File lib/puppet/dsl.rb, line 269
269:         def type
270:             self.name
271:         end

[Validate]