Created
December 13, 2016 22:54
-
-
Save kml/e59a2d32246ec53b7840e6ec9ed56041 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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