Class: ActiveRecord::Turntable::Shard
- Inherits:
-
Object
- Object
- ActiveRecord::Turntable::Shard
- Defined in:
- lib/active_record/turntable/shard.rb
Direct Known Subclasses
Defined Under Namespace
Modules: Connections
Constant Summary collapse
- DEFAULT_CONFIG =
{ "connection" => (defined?(Rails) ? Rails.env : "development") }.with_indifferent_access
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #connection ⇒ Object
- #connection_pool ⇒ Object
-
#initialize(shard_spec) ⇒ Shard
constructor
A new instance of Shard.
Constructor Details
#initialize(shard_spec) ⇒ Shard
Returns a new instance of Shard.
11 12 13 14 15 |
# File 'lib/active_record/turntable/shard.rb', line 11 def initialize(shard_spec) @config = DEFAULT_CONFIG.merge(shard_spec) @name = @config["connection"] ActiveRecord::Base.turntable_connections[name] = connection_pool end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/active_record/turntable/shard.rb', line 9 def name @name end |
Instance Method Details
#connection ⇒ Object
21 22 23 24 25 |
# File 'lib/active_record/turntable/shard.rb', line 21 def connection connection_pool.connection.tap do |conn| conn.turntable_shard_name ||= name end end |
#connection_pool ⇒ Object
17 18 19 |
# File 'lib/active_record/turntable/shard.rb', line 17 def connection_pool connection_klass.connection_pool end |