Class: Multidb::Candidate
- Inherits:
-
Object
- Object
- Multidb::Candidate
- Defined in:
- lib/multidb/candidate.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #connection(&block) ⇒ Object
- #disconnect! ⇒ Object
-
#initialize(name, target) ⇒ Candidate
constructor
A new instance of Candidate.
Constructor Details
#initialize(name, target) ⇒ Candidate
Returns a new instance of Candidate.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/multidb/candidate.rb', line 5 def initialize(name, target) @name = name case target when Hash @connection_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new @connection_handler.establish_connection(target.merge(name: 'primary')) when ActiveRecord::ConnectionAdapters::ConnectionHandler @connection_handler = target else raise ArgumentError, 'Connection handler not passed to target' end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
31 32 33 |
# File 'lib/multidb/candidate.rb', line 31 def name @name end |
Instance Method Details
#connection(&block) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/multidb/candidate.rb', line 19 def connection(&block) if block_given? @connection_handler.retrieve_connection_pool('primary').with_connection(&block) else @connection_handler.retrieve_connection('primary') end end |
#disconnect! ⇒ Object
27 28 29 |
# File 'lib/multidb/candidate.rb', line 27 def disconnect! @connection_handler.clear_all_connections! end |