Class: ActiveRecord::Sharding::ClusterConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/sharding/cluster_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ ClusterConfig

Returns a new instance of ClusterConfig.



6
7
8
9
# File 'lib/active_record/sharding/cluster_config.rb', line 6

def initialize(name)
  @name = name
  @connection_registry = []
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/active_record/sharding/cluster_config.rb', line 4

def name
  @name
end

Instance Method Details

#connectionsObject



27
28
29
# File 'lib/active_record/sharding/cluster_config.rb', line 27

def connections
  @connection_registry
end

#fetch(modulo_key) ⇒ Object



15
16
17
# File 'lib/active_record/sharding/cluster_config.rb', line 15

def fetch(modulo_key)
  @connection_registry[modulo_key]
end

#register_connection(connection_name) ⇒ Object



11
12
13
# File 'lib/active_record/sharding/cluster_config.rb', line 11

def register_connection(connection_name)
  @connection_registry << connection_name
end

#registerd_connection_countObject



19
20
21
# File 'lib/active_record/sharding/cluster_config.rb', line 19

def registerd_connection_count
  @connection_registry.count
end

#validate_config!Object



23
24
25
# File 'lib/active_record/sharding/cluster_config.rb', line 23

def validate_config!
  raise "Nothing registerd connections." if registerd_connection_count == 0
end