1
require 'puppet/parser/ast/branch'
3
# Any normal puppet object declaration. Can result in a class or a
4
# component, in addition to builtin types.
5
class Puppet::Parser::AST
6
class ResourceDef < AST::Branch
7
attr_accessor :title, :type, :exported, :virtual
10
# probably not used at all
15
# probably not used at all
20
# Iterate across all of our children.
22
[@type,@title,@params].flatten.each { |param|
23
#Puppet.debug("yielding param %s" % param)
28
# Does not actually return an object; instead sets an object
29
# in the current scope.
35
# Get our type and name.
38
# Disable definition inheritance, for now. 8/27/06, luke
39
#if objtype == "super"
40
# objtype = supertype()
46
# Evaluate all of the specified params.
47
paramobjects = @params.collect { |param|
48
param.safeevaluate(:scope => scope)
51
# Now collect info from our parent.
54
parentname = supersetup(hash)
58
# Determine our name if we have one.
60
objtitles = @title.safeevaluate(:scope => scope)
61
# it's easier to always use an array, even for only one name
62
unless objtitles.is_a?(Array)
63
objtitles = [objtitles]
67
objtitles = [parentname]
69
# See if they specified the name as a parameter instead of
70
# as a normal name (i.e., before the colon).
71
unless object # we're a builtin
72
if objclass = Puppet::Type.type(objtype)
73
namevar = objclass.namevar
75
tmp = hash["name"] || hash[namevar.to_s]
81
# This isn't grammatically legal.
82
raise Puppet::ParseError, "Got a resource with no title"
88
# This is where our implicit iteration takes place; if someone
89
# passed an array as the name, then we act just like the called us
91
objtitles.collect { |objtitle|
92
exceptwrap :type => Puppet::ParseError do
93
obj = Puppet::Parser::Resource.new(
96
:params => paramobjects,
99
:exported => self.exported || scope.exported,
100
:virtual => self.virtual,
101
:source => scope.source,
105
# And then store the resource in the scope.
106
# XXX At some point, we need to switch all of this to return
107
# objects instead of storing them like this.
108
scope.setresource(obj)
111
}.reject { |obj| obj.nil? }
114
# Create our ResourceDef. Handles type checking for us.
119
#self.typecheck(@type.value)
122
# Set the parameters for our object.
124
if params.is_a?(AST::ASTArray)
127
@params = AST::ASTArray.new(
128
:line => params.line,
129
:file => params.file,
130
:children => [params]
136
unless defined? @supercomp
137
if @scope and comp = @scope.inside
140
error = Puppet::ParseError.new(
141
"'super' is only valid within definitions"
143
error.line = self.line
144
error.file = self.file
151
# Take all of the arguments of our parent and add them into our own,
152
# without overriding anything.
156
# Now check each of the arguments from the parent.
157
comp.arguments.each do |name, value|
158
unless hash.has_key? name
163
# Return the parent name, so it can be used if appropriate.
167
# Retrieve our supertype.
169
unless defined? @supertype
170
if parent = supercomp.parentclass
173
error = Puppet::ParseError.new(
174
"%s does not have a parent class" % comp.type
176
error.line = self.line
177
error.file = self.file
184
# Print this object out.
187
@type.tree(indent + 1),
188
@title.tree(indent + 1),
189
((@@indline * indent) + self.typewrap(self.pin)),
190
@params.collect { |param|
192
param.tree(indent + 1)
193
rescue NoMethodError => detail
194
Puppet.err @params.inspect
195
error = Puppet::DevError.new(
196
"failed to tree a %s" % self.class
198
error.set_backtrace detail.backtrace
206
return "%s => { %s }" % [@title,
207
@params.collect { |param|
215
# $Id: resourcedef.rb 1726 2006-10-04 18:24:24Z luke $