summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/resource.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-12-09 17:02:29 -0600
committerLuke Kanies <luke@madstop.com>2008-12-18 11:10:21 -0600
commite3b1590f57a18b89c5f97ca0aa8e8d2bd9187b58 (patch)
tree12a504efed000f16bbe1d45e9e6f71471714ae44 /lib/puppet/parser/resource.rb
parentc306a1744793420337421f6fdf3630a9121861bd (diff)
downloadpuppet-e3b1590f57a18b89c5f97ca0aa8e8d2bd9187b58.tar.gz
puppet-e3b1590f57a18b89c5f97ca0aa8e8d2bd9187b58.tar.xz
puppet-e3b1590f57a18b89c5f97ca0aa8e8d2bd9187b58.zip
Adding resource convertion to the parser resources
Also uses Puppet::Resource's method for creating transportable resources. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet/parser/resource.rb')
-rw-r--r--lib/puppet/parser/resource.rb76
1 files changed, 32 insertions, 44 deletions
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 747338b3b..7dec02b1f 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -278,69 +278,57 @@ class Puppet::Parser::Resource
return db_resource
end
- def to_s
- self.ref
- end
-
- # Translate our object to a transportable object.
- def to_trans
- return nil if virtual?
+ # 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)
- 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_type
+ to_trans.to_type
end
private