Skip to content

Commit

Permalink
fix swap_connection_handler method definition
Browse files Browse the repository at this point in the history
  swap_connection_handler method has been removed since rails 7.1
  ref: rails/rails@1bbaf0d
  • Loading branch information
fumihumi committed Oct 25, 2023
1 parent a80d8a3 commit 965042c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/octoball/connection_handling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ class Octoball
module ConnectionHandlingAvoidAutoLoadProxy
private

def swap_connection_handler(handler, &blk)
old_handler, ActiveRecord::Base.connection_handler = ActiveRecord::Base.connection_handler, handler
return_value = yield
return_value.load if !return_value.respond_to?(:ar_relation) && return_value.is_a?(ActiveRecord::Relation)
return_value
ensure
ActiveRecord::Base.connection_handler = old_handler
if ActiveRecord.gem_version < Gem::Version.new('7.1.0')
def swap_connection_handler(handler, &blk)
old_handler, ActiveRecord::Base.connection_handler = ActiveRecord::Base.connection_handler, handler
return_value = yield
return_value.load if !return_value.respond_to?(:ar_relation) && return_value.is_a?(ActiveRecord::Relation)
return_value
ensure
ActiveRecord::Base.connection_handler = old_handler
end
end
end

Expand Down

0 comments on commit 965042c

Please sign in to comment.