Module: Mongoid::DynamicClients
- Defined in:
- lib/mongoid/dynamic_clients/version.rb,
lib/mongoid/dynamic_clients/client_switch.rb
Constant Summary collapse
- VERSION =
"1.0.0"
Instance Method Summary collapse
Instance Method Details
#with_mongoid_client(client_identifier, client_config = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/mongoid/dynamic_clients/client_switch.rb', line 4 def with_mongoid_client(client_identifier, client_config = {}) previous_client = Mongoid::Threaded.client_override cid = client_identifier.to_sym begin unless Mongoid::Config.clients[cid] Mongoid::Config.clients[cid] = client_config #Mongoid::Clients.with_name(cid).reconnect end Mongoid.override_client(cid) yield ensure Mongoid.override_client(previous_client) end end |