Skip to content

Instantly share code, notes, and snippets.

@bobishh
Created March 23, 2017 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobishh/083cb0173c55139ba2dea50d1d747082 to your computer and use it in GitHub Desktop.
Save bobishh/083cb0173c55139ba2dea50d1d747082 to your computer and use it in GitHub Desktop.
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
@bobishh
Copy link
Author

bobishh commented Mar 23, 2017

Rails 4.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment