Class: DbCharmer::Sharding::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/db_charmer/sharding/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configObject

Returns the value of attribute config.



4
5
6
# File 'lib/db_charmer/sharding/connection.rb', line 4

def config
  @config
end

#sharderObject

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_connectionObject



30
31
32
# File 'lib/db_charmer/sharding/connection.rb', line 30

def default_connection
  @default_connection ||= DbCharmer::Sharding::StubConnection.new(self)
end

#instantiate_sharderObject

Raises:

  • (ArgumentError)


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_sharderObject



18
19
20
# File 'lib/db_charmer/sharding/connection.rb', line 18

def reload_sharder
  @sharder = instantiate_sharder
end

#shard_connectionsObject



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

Returns:

  • (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