lib/adaptive_alias.rb in adaptive_alias-1.1.2 vs lib/adaptive_alias.rb in adaptive_alias-1.2.0

- old
+ new

@@ -8,12 +8,10 @@ require 'adaptive_alias/active_model_patches/arel_table' require 'adaptive_alias/patches/backward_patch' require 'adaptive_alias/patches/forward_patch' require 'adaptive_alias/hooks/association' -require 'adaptive_alias/hooks/association_scope' -require 'adaptive_alias/hooks/singular_association' require 'adaptive_alias/hooks/relation' require 'adaptive_alias/hooks/active_record_core' require 'adaptive_alias/hooks/active_record_persistence' require 'adaptive_alias/hooks/calculations' @@ -45,24 +43,15 @@ end def rescue_statement_invalid(relation: nil, reflection: nil, model: nil, &block) yield rescue ActiveRecord::StatementInvalid => error - raise error if AdaptiveAlias.current_patches.all?{|_key, patch| !patch.fix_association.call(relation, reflection, model, error) } + _key, patch = AdaptiveAlias.current_patches.find{|_key, patch| patch.check_matched.call(relation, reflection, model, error) } + raise error if patch == nil - result = rescue_statement_invalid(relation: relation, reflection: reflection, model: model, &block) - AdaptiveAlias.current_patches.each_value(&:mark_removable) - return result - end - - def rescue_missing_attribute(klass, &block) - yield - rescue ActiveModel::MissingAttributeError => error - raise error if AdaptiveAlias.current_patches.all?{|_key, patch| !patch.fix_missing_attribute.call(klass, error) } - - result = rescue_missing_attribute(klass, &block) - AdaptiveAlias.current_patches.each_value(&:mark_removable) - return result + patch.remove_and_fix_association.call(relation, reflection) do + return rescue_statement_invalid(relation: relation, reflection: reflection, model: model, &block) + end end def get_or_create_model_module(klass) return @model_modules[klass] if @model_modules[klass]