summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2009-03-13 23:30:03 +0100
committerJames Turnbull <james@lovedthanlost.net>2009-05-02 09:08:42 +1000
commitd51d87e1f04b643f4efb5c6453a2c1fc9a1ca8e5 (patch)
tree108e00dc3263ed3101e40f034e1c229cb7ccf467 /lib
parenta1c0ae0fe3c4bef6f21240c4d0a8da985cc7c8af (diff)
downloadpuppet-d51d87e1f04b643f4efb5c6453a2c1fc9a1ca8e5.tar.gz
puppet-d51d87e1f04b643f4efb5c6453a2c1fc9a1ca8e5.tar.xz
puppet-d51d87e1f04b643f4efb5c6453a2c1fc9a1ca8e5.zip
Add an unmunge capability to type parameters and properties
Unmunge is the reverse of munge. While munge allows the type to return a different parameter value or properties should than the one it was created with, unmunge does the reverse. It can be used for instance to store a value in a different representation but still be able to return genuine value to the outside world. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/parameter.rb16
-rw-r--r--lib/puppet/property.rb4
2 files changed, 17 insertions, 3 deletions
diff --git a/lib/puppet/parameter.rb b/lib/puppet/parameter.rb
index 04b3aec30..ae152de56 100644
--- a/lib/puppet/parameter.rb
+++ b/lib/puppet/parameter.rb
@@ -286,6 +286,13 @@ class Puppet::Parameter
define_method(:unsafe_munge, &block)
end
+ # Does the parameter supports reverse munge?
+ # This will be called when something wants to access the parameter
+ # in a canonical form different to what the storage form is.
+ def unmunge(&block)
+ define_method(:unmunge, &block)
+ end
+
# Mark whether we're the namevar.
def isnamevar
@isnamevar = true
@@ -446,6 +453,11 @@ class Puppet::Parameter
self.class.value_collection.munge(value)
end
+ # no unmunge by default
+ def unmunge(value)
+ value
+ end
+
# A wrapper around our munging that makes sure we raise useful exceptions.
def munge(value)
begin
@@ -482,7 +494,9 @@ class Puppet::Parameter
@resource = nil
end
- attr_reader :value
+ def value
+ unmunge(@value)
+ end
# Store the value provided. All of the checking should possibly be
# late-binding (e.g., users might not exist when the value is assigned
diff --git a/lib/puppet/property.rb b/lib/puppet/property.rb
index 3bb1a4f0c..a144f28d0 100644
--- a/lib/puppet/property.rb
+++ b/lib/puppet/property.rb
@@ -332,9 +332,9 @@ class Puppet::Property < Puppet::Parameter
[self.class.name, @resource.name]
end
if match_all?
- return @should
+ return @should.collect { |val| self.unmunge(val) }
else
- return @should[0]
+ return self.unmunge(@should[0])
end
else
return nil