summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2016-01-22 12:57:55 -0800
committerJohn Keiser <john@johnkeiser.com>2016-01-22 12:57:55 -0800
commit589e920075037e7367dcd6b728a1d954b774f0de (patch)
tree35aea32e3d0d59e70fd5dfe379ae72a9af4f8aff
parent1cb9cc67b71d21d1207602d1ec50ad2d68486171 (diff)
downloadchef-jk/block-property.tar.gz
Add ability to set a property to a blockjk/block-property
-rw-r--r--lib/chef/property.rb15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/chef/property.rb b/lib/chef/property.rb
index 8ff4ecc7fc..ef7aa521fb 100644
--- a/lib/chef/property.rb
+++ b/lib/chef/property.rb
@@ -248,7 +248,15 @@ class Chef
# will be returned without running, validating or coercing. If it is a
# `get`, the non-lazy, coerced, validated value will always be returned.
#
- def call(resource, value=NOT_PASSED)
+ def call(resource, value=NOT_PASSED, &block)
+ # Treat property { ... } the same as property proc { ... } (a setter)
+ if block
+ if value != NOT_PASSED
+ raise "Property #{name} of \#{self} cannot be passed passed *both* a block and a value at the same time." if value != NOT_PASSED && block
+ end
+ value = block
+ end
+
if value == NOT_PASSED
return get(resource)
end
@@ -479,9 +487,8 @@ class Chef
# We prefer this form because the property name won't show up in the
# stack trace if you use `define_method`.
declared_in.class_eval <<-EOM, __FILE__, __LINE__+1
- def #{name}(value=NOT_PASSED)
- raise "Property #{name} of \#{self} cannot be passed a block! If you meant to create a resource named #{name} instead, you'll need to first rename the property." if block_given?
- self.class.properties[#{name.inspect}].call(self, value)
+ def #{name}(value=NOT_PASSED, &block)
+ self.class.properties[#{name.inspect}].call(self, value, &block)
end
def #{name}=(value)
raise "Property #{name} of \#{self} cannot be passed a block! If you meant to create a resource named #{name} instead, you'll need to first rename the property." if block_given?