Class: ActiveRecordPartitioning::ConnectionPools

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord_partitioning/connection_pools.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_name, store = {}) ⇒ ConnectionPools

Returns a new instance of ConnectionPools.



8
9
10
11
# File 'lib/activerecord_partitioning/connection_pools.rb', line 8

def initialize(key_name, store={})
  @key_name = key_name
  @store = store
end

Instance Attribute Details

#key_nameObject (readonly)

Returns the value of attribute key_name.



6
7
8
# File 'lib/activerecord_partitioning/connection_pools.rb', line 6

def key_name
  @key_name
end

#storeObject (readonly)

Returns the value of attribute store.



6
7
8
# File 'lib/activerecord_partitioning/connection_pools.rb', line 6

def store
  @store
end

Instance Method Details

#[](klass_name) ⇒ Object



19
20
21
22
23
# File 'lib/activerecord_partitioning/connection_pools.rb', line 19

def [](klass_name)
  config = ActiveRecordPartitioning.current_connection_pool_config
  raise NoActiveConnectionPoolError if config.nil?
  @store[connection_pool_key(config)]
end

#[]=(klass_name, pool) ⇒ Object



25
26
27
# File 'lib/activerecord_partitioning/connection_pools.rb', line 25

def []=(klass_name, pool)
  @store[connection_pool_key(pool.spec.config)] = pool
end

#delete_if(&block) ⇒ Object



29
30
31
# File 'lib/activerecord_partitioning/connection_pools.rb', line 29

def delete_if(&block)
  @store.delete_if(&block)
end

#each(&block) ⇒ Object



37
38
39
# File 'lib/activerecord_partitioning/connection_pools.rb', line 37

def each(&block)
  @store.each(&block)
end

#each_value(&block) ⇒ Object



33
34
35
# File 'lib/activerecord_partitioning/connection_pools.rb', line 33

def each_value(&block)
  @store.each_value(&block)
end

#merge!(pools) ⇒ Object



13
14
15
16
17
# File 'lib/activerecord_partitioning/connection_pools.rb', line 13

def merge!(pools)
  pools.each do |klass_name, pool|
    self[klass_name] = pool
  end
end

#sizeObject



41
42
43
# File 'lib/activerecord_partitioning/connection_pools.rb', line 41

def size
  @store.size
end