summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-07-10 19:30:39 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-07-10 19:30:39 +0000
commit9f685e6da1f58f7011864f832e7a4a362870f93f (patch)
tree3a117120ff43d13369eb8158e3882b8692f42006 /lib/puppet
parentc8801b7886bf18a97cc5b7cf70d37a54867d7978 (diff)
downloadpuppet-9f685e6da1f58f7011864f832e7a4a362870f93f.tar.gz
puppet-9f685e6da1f58f7011864f832e7a4a362870f93f.tar.xz
puppet-9f685e6da1f58f7011864f832e7a4a362870f93f.zip
Adding support in Property for declarating whether a given property type will match all @should values or just the first.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2674 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/property.rb43
1 files changed, 37 insertions, 6 deletions
diff --git a/lib/puppet/property.rb b/lib/puppet/property.rb
index a7e79c9c5..2f23b07f8 100644
--- a/lib/puppet/property.rb
+++ b/lib/puppet/property.rb
@@ -19,6 +19,24 @@ class Property < Puppet::Parameter
attr_accessor :unmanaged
attr_reader :name
+ # Return array matching info, defaulting to just matching
+ # the first value.
+ def array_matching
+ unless defined?(@array_matching)
+ @array_matching = :first
+ end
+ @array_matching
+ end
+
+ # Set whether properties should match all values or just the first one.
+ def array_matching=(value)
+ value = value.intern if value.is_a?(String)
+ unless [:first, :all].include?(value)
+ raise ArgumentError, "Supported values for Property#array_matching are 'first' and 'all'"
+ end
+ @array_matching = value
+ end
+
def checkable
@checkable = true
end
@@ -255,11 +273,15 @@ class Property < Puppet::Parameter
end
# Look for a matching value
- @should.each { |val|
- if is == val or is == val.to_s
- return true
- end
- }
+ if match_all?
+ return (is == @should or is == @should.collect { |v| v.to_s })
+ else
+ @should.each { |val|
+ if is == val or is == val.to_s
+ return true
+ end
+ }
+ end
# otherwise, return false
return false
@@ -286,6 +308,11 @@ class Property < Puppet::Parameter
)
end
+ # Should we match all values, or just the first?
+ def match_all?
+ self.class.array_matching == :all
+ end
+
# each property class must define the name() method, and property instances
# do not change that name
# this implicitly means that a given object can only have one property
@@ -352,7 +379,11 @@ class Property < Puppet::Parameter
self.devfail "should for %s on %s is not an array" %
[self.class.name, @resource.name]
end
- return @should[0]
+ if match_all?
+ return @should
+ else
+ return @should[0]
+ end
else
return nil
end