diff options
author | Luke Kanies <luke@madstop.com> | 2008-12-16 17:56:53 -0600 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-12-18 11:10:24 -0600 |
commit | 1c7f8f685d3beec267f7e45e7d1217d7db770082 (patch) | |
tree | 2e5bb7f538aa90318cfb94a9b65e27796f2137dc /lib | |
parent | e601babb9266258f55580fcf2a91ea5ca4c5d368 (diff) | |
download | puppet-1c7f8f685d3beec267f7e45e7d1217d7db770082.tar.gz puppet-1c7f8f685d3beec267f7e45e7d1217d7db770082.tar.xz puppet-1c7f8f685d3beec267f7e45e7d1217d7db770082.zip |
Adding name/namevar abstraction to Puppet::Resource.
This hopefully provides a single place to manage this
complexity, and I'll be using it to simplify Puppet::Type.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/resource.rb | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb index db06667e7..d82a7f996 100644 --- a/lib/puppet/resource.rb +++ b/lib/puppet/resource.rb @@ -7,7 +7,7 @@ require 'puppet/resource/reference' class Puppet::Resource include Puppet::Util::Tagging include Enumerable - attr_accessor :type, :title, :file, :line, :catalog + attr_accessor :type, :title, :file, :line, :catalog, :implicit # Proxy these methods to the parameters hash. It's likely they'll # be overridden at some point, but this works for now. @@ -64,7 +64,14 @@ class Puppet::Resource # Produce a simple hash of our parameters. def to_hash - @parameters.dup + result = @parameters.dup + unless result.include?(namevar) + result[namevar] = title + end + if result.has_key?(nil) + raise "wtf? %s" % namevar.inspect + end + result end def to_s @@ -146,6 +153,30 @@ class Puppet::Resource private + # Produce a canonical method name. + def parameter_name(param) + param = param.to_s.downcase.to_sym + if param == :name and n = namevar() + param = namevar + end + param + end + + # The namevar for our resource type. If the type doesn't exist, + # always use :name. + def namevar + if t = resource_type + t.namevar + else + :name + end + end + + # Retrieve the resource type. + def resource_type + Puppet::Type.type(type) + end + # Create an old-style TransBucket instance, for non-builtin resource types. def to_transbucket bucket = Puppet::TransBucket.new([]) @@ -156,9 +187,4 @@ class Puppet::Resource # TransBuckets don't support parameters, which is why they're being deprecated. return bucket end - - # Produce a canonical method name. - def parameter_name(param) - param.to_s.downcase.to_sym - end end |