aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorArthur Neves <arthurnn@gmail.com>2013-10-17 09:53:43 -0400
committerArthur Neves <arthurnn@gmail.com>2013-10-17 09:53:43 -0400
commit827d42e1d140aef97462802ecdfee69c4b75ebca (patch)
tree8d06efa49e7fd6f93408a562c20e4a45b935bd6b /activerecord
parentb4bda6565136eb82ba49dc37c6dbfc61b573e2ef (diff)
downloadrails-827d42e1d140aef97462802ecdfee69c4b75ebca.tar.gz
rails-827d42e1d140aef97462802ecdfee69c4b75ebca.tar.bz2
rails-827d42e1d140aef97462802ecdfee69c4b75ebca.zip
Make define_non_cyclic_method simpler
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/autosave_association.rb14
1 files changed, 7 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb
index b30d1eb0a6..f31cbb499c 100644
--- a/activerecord/lib/active_record/autosave_association.rb
+++ b/activerecord/lib/active_record/autosave_association.rb
@@ -143,16 +143,16 @@ module ActiveRecord
module ClassMethods
private
- def define_non_cyclic_method(name, reflection, &block)
+ def define_non_cyclic_method(name, &block)
define_method(name) do |*args|
result = true; @_already_called ||= {}
# Loop prevention for validation of associations
- unless @_already_called[[name, reflection.name]]
+ unless @_already_called[name]
begin
- @_already_called[[name, reflection.name]]=true
+ @_already_called[name]]=true
result = instance_eval(&block)
ensure
- @_already_called[[name, reflection.name]]=false
+ @_already_called[name]=false
end
end
@@ -180,7 +180,7 @@ module ActiveRecord
if collection
before_save :before_save_collection_association
- define_non_cyclic_method(save_method, reflection) { save_collection_association(reflection) }
+ define_non_cyclic_method(save_method) { save_collection_association(reflection) }
# Doesn't use after_save as that would save associations added in after_create/after_update twice
after_create save_method
after_update save_method
@@ -197,14 +197,14 @@ module ActiveRecord
after_create save_method
after_update save_method
else
- define_non_cyclic_method(save_method, reflection) { save_belongs_to_association(reflection) }
+ define_non_cyclic_method(save_method) { save_belongs_to_association(reflection) }
before_save save_method
end
end
if reflection.validate? && !method_defined?(validation_method)
method = (collection ? :validate_collection_association : :validate_single_association)
- define_non_cyclic_method(validation_method, reflection) { send(method, reflection) }
+ define_non_cyclic_method(validation_method) { send(method, reflection) }
validate validation_method
end
end