Class: ActiveRecordPartitioning::ConnectionPools

Inherits:
Object
  • Object
show all
Includes:
Enumerable
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.



10
11
12
13
# File 'lib/activerecord_partitioning/connection_pools.rb', line 10

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.



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

def key_name
  @key_name
end

#storeObject (readonly)

Returns the value of attribute store.



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

def store
  @store
end

Instance Method Details

#[](klass_name) ⇒ Object



21
22
23
24
25
# File 'lib/activerecord_partitioning/connection_pools.rb', line 21

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

#[]=(klass_name, pool) ⇒ Object



27
28
29
# File 'lib/activerecord_partitioning/connection_pools.rb', line 27

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

#delete_if(&block) ⇒ Object



31
32
33
# File 'lib/activerecord_partitioning/connection_pools.rb', line 31

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

#each(&block) ⇒ Object



39
40
41
# File 'lib/activerecord_partitioning/connection_pools.rb', line 39

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

#each_value(&block) ⇒ Object



35
36
37
# File 'lib/activerecord_partitioning/connection_pools.rb', line 35

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

#keysObject



47
48
49
# File 'lib/activerecord_partitioning/connection_pools.rb', line 47

def keys
  @store.keys
end

#merge!(pools) ⇒ Object



15
16
17
18
19
# File 'lib/activerecord_partitioning/connection_pools.rb', line 15

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

#sizeObject



51
52
53
# File 'lib/activerecord_partitioning/connection_pools.rb', line 51

def size
  @store.size
end

#valuesObject



43
44
45
# File 'lib/activerecord_partitioning/connection_pools.rb', line 43

def values
  @store.values
end