Cleaning up the AST::Resource code a bit

Mostly renaming 'obj' to 'resource', since the whole
'obj' thing is a holdover from before we had the
term 'resource'.

Also pulling a bit of code out of a loop, since it
didn't need to be there.

Signed-off-by: Luke Kanies <luke@madstop.com>
This commit is contained in:
Luke Kanies 2009-02-10 14:59:18 -06:00
Родитель b22d148e6d
Коммит 0e491591d2
1 изменённых файлов: 21 добавлений и 20 удалений

Просмотреть файл

@ -18,34 +18,35 @@ class Resource < AST::ResourceReference
param.safeevaluate(scope) param.safeevaluate(scope)
} }
objtitles = @title.safeevaluate(scope) resource_titles = @title.safeevaluate(scope)
# it's easier to always use an array, even for only one name # it's easier to always use an array, even for only one name
unless objtitles.is_a?(Array) unless resource_titles.is_a?(Array)
objtitles = [objtitles] resource_titles = [resource_titles]
end end
objtype = qualified_type(scope) resource_type = qualified_type(scope)
# We want virtual to be true if exported is true. We can't
# just set :virtual => self.virtual in the initialization,
# because sometimes the :virtual attribute is set *after*
# :exported, in which case it clobbers :exported if :exported
# is true. Argh, this was a very tough one to track down.
exp = self.exported || scope.resource.exported?
virt = self.virtual || scope.resource.virtual? || exp
# This is where our implicit iteration takes place; if someone # This is where our implicit iteration takes place; if someone
# passed an array as the name, then we act just like the called us # passed an array as the name, then we act just like the called us
# many times. # many times.
objtitles.flatten.collect { |objtitle| resource_titles.flatten.collect { |resource_title|
exceptwrap :type => Puppet::ParseError do exceptwrap :type => Puppet::ParseError do
exp = self.exported || scope.resource.exported? resource = Puppet::Parser::Resource.new(
# We want virtual to be true if exported is true. We can't :type => resource_type,
# just set :virtual => self.virtual in the initialization, :title => resource_title,
# because sometimes the :virtual attribute is set *after*
# :exported, in which case it clobbers :exported if :exported
# is true. Argh, this was a very tough one to track down.
virt = self.virtual || scope.resource.virtual? || exp
obj = Puppet::Parser::Resource.new(
:type => objtype,
:title => objtitle,
:params => paramobjects, :params => paramobjects,
:file => self.file, :file => self.file,
:line => self.line, :line => self.line,
:exported => exp, :exported => self.exported,
:virtual => virt, :virtual => virt,
:source => scope.source, :source => scope.source,
:scope => scope :scope => scope
@ -53,11 +54,11 @@ class Resource < AST::ResourceReference
# And then store the resource in the compiler. # And then store the resource in the compiler.
# At some point, we need to switch all of this to return # At some point, we need to switch all of this to return
# objects instead of storing them like this. # resources instead of storing them like this.
scope.compiler.add_resource(scope, obj) scope.compiler.add_resource(scope, resource)
obj resource
end end
}.reject { |obj| obj.nil? } }.reject { |resource| resource.nil? }
end end
# Set the parameters for our object. # Set the parameters for our object.