aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-03-18 12:16:54 -0700
committerwycats <wycats@gmail.com>2010-03-27 01:41:44 -0700
commit3172db12e4e7f6abab8ddd25f7911d29a5b65ea0 (patch)
tree8f3d6e7eeca690dd9d7d7d6d54d45b0b96d571ec
parent753304bd113d7524f6d48d220483a2723c534557 (diff)
downloadrails-3172db12e4e7f6abab8ddd25f7911d29a5b65ea0.tar.gz
rails-3172db12e4e7f6abab8ddd25f7911d29a5b65ea0.tar.bz2
rails-3172db12e4e7f6abab8ddd25f7911d29a5b65ea0.zip
avoiding a few closure references by evaling. [#4223 state:resolved]
Signed-off-by: wycats <wycats@gmail.com>
-rwxr-xr-xactiverecord/lib/active_record/associations.rb30
1 files changed, 18 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 726e6b8b81..d623ddb915 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1545,15 +1545,19 @@ module ActiveRecord
case name
when :destroy, :delete
- define_method(method_name) do
- association = send(reflection.name)
- association.send(name) if association
- end
+ class_eval <<-eoruby, __FILE__, __LINE__ + 1
+ def #{method_name}
+ association = #{reflection.name}
+ association.#{name} if association
+ end
+ eoruby
when :nullify
- define_method(method_name) do
- association = send(reflection.name)
- association.update_attribute(reflection.primary_key_name, nil) if association
- end
+ class_eval <<-eoruby, __FILE__, __LINE__ + 1
+ def #{method_name}
+ association = #{reflection.name}
+ association.update_attribute(#{reflection.primary_key_name.inspect}, nil) if association
+ end
+ eoruby
else
raise ArgumentError, "The :dependent option expects either :destroy, :delete or :nullify (#{reflection.options[:dependent].inspect})"
end
@@ -1571,10 +1575,12 @@ module ActiveRecord
end
method_name = :"belongs_to_dependent_#{name}_for_#{reflection.name}"
- define_method(method_name) do
- association = send(reflection.name)
- association.send(name) if association
- end
+ class_eval <<-eoruby, __FILE__, __LINE__ + 1
+ def #{method_name}
+ association = #{reflection.name}
+ association.#{name} if association
+ end
+ eoruby
after_destroy method_name
end
end