Class: Noiseless::ConnectionManager
- Inherits:
-
Object
- Object
- Noiseless::ConnectionManager
- Defined in:
- lib/noiseless/connection_manager.rb
Instance Method Summary collapse
-
#client(name = :primary) ⇒ Object
Retrieve a client; defaults to :primary.
-
#initialize ⇒ ConnectionManager
constructor
A new instance of ConnectionManager.
-
#register(name, adapter:, hosts:) ⇒ Object
Register a named client statically from YAML (boot-time only).
Constructor Details
#initialize ⇒ ConnectionManager
Returns a new instance of ConnectionManager.
5 6 7 8 |
# File 'lib/noiseless/connection_manager.rb', line 5 def initialize @clients = {} @configs = {} end |
Instance Method Details
#client(name = :primary) ⇒ Object
Retrieve a client; defaults to :primary
16 17 18 19 20 21 22 23 24 |
# File 'lib/noiseless/connection_manager.rb', line 16 def client(name = :primary) name = name.to_sym # Lazy-load the adapter only when actually used @clients[name] ||= begin config = @configs.fetch(name) { raise "Unknown connection: #{name}" } Adapters.lookup(config[:adapter], hosts: config[:hosts]) end end |
#register(name, adapter:, hosts:) ⇒ Object
Register a named client statically from YAML (boot-time only)
11 12 13 |
# File 'lib/noiseless/connection_manager.rb', line 11 def register(name, adapter:, hosts:) @configs[name.to_sym] = { adapter: adapter, hosts: hosts } end |