diff options
author | Xabier de Zuazo <xabier@onddo.com> | 2014-11-27 22:44:10 +0100 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-01-27 11:59:40 -0800 |
commit | 8b4b26b6858e681a6d9d1c65abd7f97f68ee42c1 (patch) | |
tree | 456517466a8e2d5a63ac812cada43b5275b3f30e /lib/chef/node | |
parent | 9e6a0cdda93de380093c4abdfeb563d6f946223b (diff) | |
download | chef-8b4b26b6858e681a6d9d1c65abd7f97f68ee42c1.tar.gz |
Use #define_method instead of #class_eval (ruby 1.8 specific, issue #2497)
Diffstat (limited to 'lib/chef/node')
-rw-r--r-- | lib/chef/node/attribute.rb | 8 | ||||
-rw-r--r-- | lib/chef/node/attribute_collections.rb | 20 | ||||
-rw-r--r-- | lib/chef/node/immutable_collections.rb | 14 |
3 files changed, 15 insertions, 27 deletions
diff --git a/lib/chef/node/attribute.rb b/lib/chef/node/attribute.rb index 80f5ac4f8d..9d8738f637 100644 --- a/lib/chef/node/attribute.rb +++ b/lib/chef/node/attribute.rb @@ -138,11 +138,9 @@ class Chef :values, :values_at, :zip].each do |delegated_method| - class_eval(<<-METHOD_DEFN) - def #{delegated_method}(*args, &block) - merged_attributes.send(:#{delegated_method}, *args, &block) - end - METHOD_DEFN + define_method(delegated_method) do |*args, &block| + merged_attributes.send(delegated_method, *args, &block) + end end # return the cookbook level default attribute component diff --git a/lib/chef/node/attribute_collections.rb b/lib/chef/node/attribute_collections.rb index 333f4864c6..b912904534 100644 --- a/lib/chef/node/attribute_collections.rb +++ b/lib/chef/node/attribute_collections.rb @@ -61,12 +61,10 @@ class Chef # also invalidate the cached merged_attributes on the root # Node::Attribute object. MUTATOR_METHODS.each do |mutator| - class_eval(<<-METHOD_DEFN, __FILE__, __LINE__) - def #{mutator}(*args, &block) - root.reset_cache(root.top_level_breadcrumb) - super - end - METHOD_DEFN + define_method(mutator) do |*args, &block| + root.reset_cache(root.top_level_breadcrumb) + super(*args, &block) + end end attr_reader :root @@ -126,12 +124,10 @@ class Chef # also invalidate the cached `merged_attributes` on the root Attribute # object. MUTATOR_METHODS.each do |mutator| - class_eval(<<-METHOD_DEFN, __FILE__, __LINE__) - def #{mutator}(*args, &block) - root.reset_cache(root.top_level_breadcrumb) - super - end - METHOD_DEFN + define_method(mutator) do |*args, &block| + root.reset_cache(root.top_level_breadcrumb) + super(*args, &block) + end end def initialize(root, data={}) diff --git a/lib/chef/node/immutable_collections.rb b/lib/chef/node/immutable_collections.rb index 56b8fed3b7..0e2800641a 100644 --- a/lib/chef/node/immutable_collections.rb +++ b/lib/chef/node/immutable_collections.rb @@ -75,12 +75,9 @@ class Chef # Redefine all of the methods that mutate a Hash to raise an error when called. # This is the magic that makes this object "Immutable" DISALLOWED_MUTATOR_METHODS.each do |mutator_method_name| - # 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) - raise Exceptions::ImmutableAttributeModification - end - METHOD_DEFN + define_method(mutator_method_name) do |*args, &block| + raise Exceptions::ImmutableAttributeModification + end end # For elements like Fixnums, true, nil... @@ -164,12 +161,9 @@ class Chef # Redefine all of the methods that mutate a Hash to raise an error when called. # This is the magic that makes this object "Immutable" DISALLOWED_MUTATOR_METHODS.each do |mutator_method_name| - # 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) + define_method(mutator_method_name) do |*args, &block| raise Exceptions::ImmutableAttributeModification end - METHOD_DEFN end def method_missing(symbol, *args) |