Skip to content

Instantly share code, notes, and snippets.

@kml
Created December 13, 2016 22:54
Show Gist options
  • Save kml/e59a2d32246ec53b7840e6ec9ed56041 to your computer and use it in GitHub Desktop.
Save kml/e59a2d32246ec53b7840e6ec9ed56041 to your computer and use it in GitHub Desktop.
# encoding: utf-8
module ImplicitConnectionForbidder
def self.forbid_implicit_connections
yield
end
end
# http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ConnectionPool.html#method-i-with_connection
# http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ConnectionPool.html#method-i-release_connection
module Kernel
def allow_connection(&block)
ActiveRecord::Base.connection_pool.with_connection(&block)
ensure
begin
ActiveRecord::Base.connection_pool.release_connection
rescue ActiveRecord::ConnectionNotEstablished
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment