Created
March 23, 2017 08:26
-
-
Save bobishh/083cb0173c55139ba2dea50d1d747082 to your computer and use it in GitHub Desktop.
This file contains 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
module Writeable | |
module Mixin | |
def self.included(base) | |
base.extend ClassMethods | |
end | |
module ClassMethods | |
def retrieve_connection | |
@pool ||= connection_handler.connection_pool_list.select do |p| | |
p.spec.config[:writeable] == true | |
end.first | |
@pool.try(:connection) || begin | |
establish_connection(:writeable) | |
retrieve_connection | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rails 4.2