diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2014-11-18 22:50:35 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2014-11-18 22:50:35 -0800 |
commit | dc76a7b655146b91d4096eeb1f5bc3e8dd022e62 (patch) | |
tree | ab5a321637645d59ec7a0589a146af2653addb63 | |
parent | 80e37a39f47899adc978c3e4b8c381f8f212814d (diff) | |
download | chef-lcg/lazy-deep-merge2.tar.gz |
fix ImmutableAttributeModification exceptionlcg/lazy-deep-merge2
-rw-r--r-- | lib/chef/exceptions.rb | 7 | ||||
-rw-r--r-- | lib/chef/node/attribute.rb | 2 | ||||
-rw-r--r-- | lib/chef/node/immutable_collections.rb | 8 |
3 files changed, 9 insertions, 8 deletions
diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb index 25f08455fc..87d472c236 100644 --- a/lib/chef/exceptions.rb +++ b/lib/chef/exceptions.rb @@ -155,7 +155,12 @@ class Chef # Node::Attribute computes the merged version of of attributes # and makes it read-only. Attempting to modify a read-only # attribute will cause this error. - class ImmutableAttributeModification < NoMethodError; end + class ImmutableAttributeModification < NoMethodError + def initialize + super "Node attributes are read-only when you do not specify which precedence level to set. " + + %Q(To set an attribute use code like `node.default["key"] = "value"') + end + end # Merged node attributes are invalidated when the component # attributes are updated. Attempting to read from a stale copy diff --git a/lib/chef/node/attribute.rb b/lib/chef/node/attribute.rb index 56034a60e4..dc97aa600b 100644 --- a/lib/chef/node/attribute.rb +++ b/lib/chef/node/attribute.rb @@ -381,7 +381,7 @@ class Chef end def []=(key, value) - raise "this should just raise an immutable attribute exception" + raise Exceptions::ImmutableAttributeModification end def has_key?(key) diff --git a/lib/chef/node/immutable_collections.rb b/lib/chef/node/immutable_collections.rb index 3558ba3a86..af04ef26d4 100644 --- a/lib/chef/node/immutable_collections.rb +++ b/lib/chef/node/immutable_collections.rb @@ -78,9 +78,7 @@ class Chef # Ruby 1.8 blocks can't have block arguments, so we must use string eval: class_eval(<<-METHOD_DEFN, __FILE__, __LINE__) def #{mutator_method_name}(*args, &block) - msg = "Node attributes are read-only when you do not specify which precedence level to set. " + - %Q(To set an attribute use code like `node.default["key"] = "value"') - raise Exceptions::ImmutableAttributeModification, msg + raise Exceptions::ImmutableAttributeModification end METHOD_DEFN end @@ -165,9 +163,7 @@ class Chef # Ruby 1.8 blocks can't have block arguments, so we must use string eval: class_eval(<<-METHOD_DEFN, __FILE__, __LINE__) def #{mutator_method_name}(*args, &block) - msg = "Node attributes are read-only when you do not specify which precedence level to set. " + - %Q(To set an attribute use code like `node.default["key"] = "value"') - raise Exceptions::ImmutableAttributeModification, msg + raise Exceptions::ImmutableAttributeModification end METHOD_DEFN end |