Class: DbCharmer::Sharding::Connection
- Defined in:
- lib/db_charmer/sharding/connection.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#sharder ⇒ Object
Returns the value of attribute sharder.
Instance Method Summary collapse
- #default_connection ⇒ Object
-
#initialize(config) ⇒ Connection
constructor
A new instance of Connection.
- #instantiate_sharder ⇒ Object
- #reload_sharder ⇒ Object
- #shard_connections ⇒ Object
- #support_default_shard? ⇒ Boolean
Constructor Details
#initialize(config) ⇒ Connection
Returns a new instance of Connection.
6 7 8 9 |
# File 'lib/db_charmer/sharding/connection.rb', line 6 def initialize(config) @config = config @sharder = self.instantiate_sharder end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
4 5 6 |
# File 'lib/db_charmer/sharding/connection.rb', line 4 def config @config end |
#sharder ⇒ Object
Returns the value of attribute sharder.
4 5 6 |
# File 'lib/db_charmer/sharding/connection.rb', line 4 def sharder @sharder end |
Instance Method Details
#default_connection ⇒ Object
30 31 32 |
# File 'lib/db_charmer/sharding/connection.rb', line 30 def default_connection @default_connection ||= DbCharmer::Sharding::StubConnection.new(self) end |
#instantiate_sharder ⇒ Object
11 12 13 14 15 16 |
# File 'lib/db_charmer/sharding/connection.rb', line 11 def instantiate_sharder raise ArgumentError, "No :method passed!" unless config[:method] sharder_class_name = "DbCharmer::Sharding::Method::#{config[:method].to_s.classify}" sharder_class = sharder_class_name.constantize sharder_class.new(config) end |
#reload_sharder ⇒ Object
18 19 20 |
# File 'lib/db_charmer/sharding/connection.rb', line 18 def reload_sharder @sharder = instantiate_sharder end |
#shard_connections ⇒ Object
22 23 24 |
# File 'lib/db_charmer/sharding/connection.rb', line 22 def shard_connections sharder.respond_to?(:shard_connections) ? sharder.shard_connections : nil end |
#support_default_shard? ⇒ Boolean
26 27 28 |
# File 'lib/db_charmer/sharding/connection.rb', line 26 def support_default_shard? sharder.respond_to?(:support_default_shard?) && sharder.support_default_shard? end |