summaryrefslogtreecommitdiff
path: root/lib/chef/property.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/property.rb')
-rw-r--r--lib/chef/property.rb12
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