diff options
author | John Keiser <john@johnkeiser.com> | 2015-12-10 12:22:08 -0800 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-12-10 15:04:55 -0800 |
commit | e7dd77496a008e4c330c63ab172fba75c6e70332 (patch) | |
tree | 34b049bdb5f16099c10e81b856f08a7e8bc9d66e /lib/chef/property.rb | |
parent | 519e4b0dc38c9f48c42915d8c9a83ef3e69e680e (diff) | |
download | chef-e7dd77496a008e4c330c63ab172fba75c6e70332.tar.gz |
Get rid of ambiguity with `template 'x' do ...`jk/error-on-property-with-block
Diffstat (limited to 'lib/chef/property.rb')
-rw-r--r-- | lib/chef/property.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/chef/property.rb b/lib/chef/property.rb index 2c7cde8651..b2658235f2 100644 --- a/lib/chef/property.rb +++ b/lib/chef/property.rb @@ -116,6 +116,10 @@ class Chef options[:instance_variable_name] = options[:instance_variable_name].to_sym if options[:instance_variable_name] end + def to_s + name + end + # # The name of this property. # @@ -470,18 +474,22 @@ class Chef # 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) 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? self.class.properties[#{name.inspect}].set(self, value) end EOM rescue SyntaxError # If the name is not a valid ruby name, we use define_method. - declared_in.define_method(name) do |value=NOT_PASSED| + declared_in.define_method(name) do |value=NOT_PASSED, &block| + 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 self.class.properties[name].call(self, value) end - declared_in.define_method("#{name}=") do |value| + declared_in.define_method("#{name}=") do |value, &block| + 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 self.class.properties[name].set(self, value) end end |