diff options
author | Markus Roberts <Markus@reality.com> | 2009-10-26 23:09:07 -0700 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-11-14 09:08:53 +1100 |
commit | ca56aa7e5849a5489e8d38e29b25ea934caafcd7 (patch) | |
tree | d144a73d0fcae991281f688284c09283510f965d /lib/puppet/parameter.rb | |
parent | adc0a4ed939a717e8735485d493bde28ceab5ac0 (diff) | |
download | puppet-ca56aa7e5849a5489e8d38e29b25ea934caafcd7.tar.gz puppet-ca56aa7e5849a5489e8d38e29b25ea934caafcd7.tar.xz puppet-ca56aa7e5849a5489e8d38e29b25ea934caafcd7.zip |
Least kludgy patch for #2675
This makes parameters responsible for the canonicalization of their values and
provides a default (passthrough) implementation. It changes munge to pre-
canonicalize the value and resource references to builtin types to canonicalize
titles (which map to resorce namevars) with the corresponding parameter's
classes's canonicalization.
It adds a canonicalization routine to file paths that normalizes the behaviour
(trailing slashes are ignored) and DRYs up the related code.
Signed-off-by: Markus Roberts <Markus@reality.com>
Diffstat (limited to 'lib/puppet/parameter.rb')
-rw-r--r-- | lib/puppet/parameter.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/puppet/parameter.rb b/lib/puppet/parameter.rb index f4086671d..58a91477a 100644 --- a/lib/puppet/parameter.rb +++ b/lib/puppet/parameter.rb @@ -293,6 +293,13 @@ class Puppet::Parameter define_method(:unmunge, &block) end + # Optionaly convert the value to a canonical form so that it will + # be found in hashes, etc. Mostly useful for namevars. + def to_canonicalize(&block) + metaclass = (class << self; self; end) + metaclass.send(:define_method,:canonicalize,&block) + end + # Mark whether we're the namevar. def isnamevar @isnamevar = true @@ -464,10 +471,19 @@ class Puppet::Parameter value end + # Assume the value is already in canonical form by default + def self.canonicalize(value) + value + end + + def canonicalize(value) + self.class.canonicalize(value) + end + # A wrapper around our munging that makes sure we raise useful exceptions. def munge(value) begin - ret = unsafe_munge(value) + ret = unsafe_munge(canonicalize(value)) rescue Puppet::Error => detail Puppet.debug "Reraising %s" % detail raise |