summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/resource.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/parser/resource.rb')
-rw-r--r--lib/puppet/parser/resource.rb80
1 files changed, 35 insertions, 45 deletions
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 2fdd78ddf..d4c7a1f0f 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -176,7 +176,7 @@ class Puppet::Parser::Resource
db_resource.file = self.file
end
- updated_params = @params.inject({}) do |hash, ary|
+ updated_params = @params.reject { |name, param| param.value == :undef }.inject({}) do |hash, ary|
hash[ary[0].to_s] = ary[1]
hash
end
@@ -270,6 +270,7 @@ class Puppet::Parser::Resource
db_resource.save
@params.each { |name, param|
+ next if param.value == :undef
param.to_rails(db_resource)
}
@@ -278,69 +279,57 @@ class Puppet::Parser::Resource
return db_resource
end
- def to_s
- self.ref
- end
+ # Create a Puppet::Resource instance from this parser resource.
+ # We plan, at some point, on not needing to do this conversion, but
+ # it's sufficient for now.
+ def to_resource
+ result = Puppet::Resource.new(type, title)
- # Translate our object to a transportable object.
- def to_trans
- return nil if virtual?
-
- if builtin?
- to_transobject
- else
- to_transbucket
- end
- end
-
- def to_transbucket
- bucket = Puppet::TransBucket.new([])
-
- bucket.type = self.type
- bucket.name = self.title
-
- # TransBuckets don't support parameters, which is why they're being deprecated.
- return bucket
- end
-
- # Convert this resource to a RAL resource. We hackishly go via the
- # transportable stuff.
- def to_type
- to_trans.to_type
- end
-
- def to_transobject
- # Now convert to a transobject
- obj = Puppet::TransObject.new(@ref.title, @ref.type)
to_hash.each do |p, v|
- if v.is_a?(Reference)
- v = v.to_ref
+ if v.is_a?(Puppet::Parser::Resource::Reference)
+ v = Puppet::Resource::Reference.new(v.type, v.title)
elsif v.is_a?(Array)
- v = v.collect { |av|
- if av.is_a?(Reference)
- av = av.to_ref
+ v = v.collect do |av|
+ if av.is_a?(Puppet::Parser::Resource::Reference)
+ av = Puppet::Resource::Reference.new(av.type, av.title)
end
av
- }
+ end
end
# If the value is an array with only one value, then
# convert it to a single value. This is largely so that
# the database interaction doesn't have to worry about
# whether it returns an array or a string.
- obj[p.to_s] = if v.is_a?(Array) and v.length == 1
+ result[p] = if v.is_a?(Array) and v.length == 1
v[0]
else
v
end
end
- obj.file = self.file
- obj.line = self.line
+ result.file = self.file
+ result.line = self.line
+ result.tag(*self.tags)
+
+ return result
+ end
+
+ def to_s
+ self.ref
+ end
+
+ # Translate our object to a transportable object.
+ def to_trans
+ return nil if virtual?
- obj.tags = self.tags
+ return to_resource.to_trans
+ end
- return obj
+ # Convert this resource to a RAL resource. We hackishly go via the
+ # transportable stuff.
+ def to_ral
+ to_resource.to_ral
end
private
@@ -364,6 +353,7 @@ class Puppet::Parser::Resource
# LAK:NOTE Relationship metaparams get treated specially -- we stack them, instead of
# overriding.
next if @params[name] and not self.class.relationship_parameter?(name)
+ next if @params[name] and @params[name].value == :undef
# Skip metaparams for which we get no value.
next unless val = scope.lookupvar(name.to_s, false) and val != :undefined