Skip to content
Browse files

Make define_non_cyclic_method simpler

  • Loading branch information...
1 parent b4bda65 commit 827d42e1d140aef97462802ecdfee69c4b75ebca @arthurnn arthurnn committed Oct 17, 2013
Showing with 7 additions and 7 deletions.
  1. +7 −7 activerecord/lib/active_record/autosave_association.rb
View
14 activerecord/lib/active_record/autosave_association.rb
@@ -143,16 +143,16 @@ def self.valid_options
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 @@ def add_autosave_association_callbacks(reflection)
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 @@ def add_autosave_association_callbacks(reflection)
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

0 comments on commit 827d42e

Please sign in to comment.
Something went wrong with that request. Please try again.