From 827d42e1d140aef97462802ecdfee69c4b75ebca Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Thu, 17 Oct 2013 09:53:43 -0400 Subject: Make define_non_cyclic_method simpler --- activerecord/lib/active_record/autosave_association.rb | 14 +++++++------- 1 file 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 -- cgit v1.2.3