Class: Tzispa::Data::AdapterPool
- Inherits:
-
Object
- Object
- Tzispa::Data::AdapterPool
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/tzispa/data/adapter_pool.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
3600
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
Instance Method Summary collapse
- #[](name = nil) ⇒ Object
-
#initialize(config, default = nil) ⇒ AdapterPool
constructor
A new instance of AdapterPool.
- #setup_sequel ⇒ Object
Constructor Details
#initialize(config, default = nil) ⇒ AdapterPool
Returns a new instance of AdapterPool.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tzispa/data/adapter_pool.rb', line 16 def initialize(config, default = nil) setup_sequel @default = default || config.first[0] @pool = {}.tap do |hsh| config.each do |k, v| conn = Sequel.connect "#{v.adapter}://#{v.database}" if v.connection_validation conn.extension(:connection_validator) conn.pool.connection_validation_timeout = v.validation_timeout || DEFAULT_TIMEOUT end hsh[k.to_sym] = conn end end end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
14 15 16 |
# File 'lib/tzispa/data/adapter_pool.rb', line 14 def default @default end |
Instance Method Details
#[](name = nil) ⇒ Object
31 32 33 |
# File 'lib/tzispa/data/adapter_pool.rb', line 31 def [](name = nil) @pool[name&.to_sym || default] end |
#setup_sequel ⇒ Object
35 36 37 38 39 |
# File 'lib/tzispa/data/adapter_pool.rb', line 35 def setup_sequel Sequel.extension :core_extensions Sequel.default_timezone = :utc Sequel.datetime_class = DateTime end |