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
26
27
28
29
30
31
32
# File 'lib/activerecord_partitioning/connection_pools.rb', line 21

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

#[]=(klass_name, pool) ⇒ Object



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

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

#delete_if(&block) ⇒ Object



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

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

#each(&block) ⇒ Object



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

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

#each_value(&block) ⇒ Object



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

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

#keysObject



54
55
56
# File 'lib/activerecord_partitioning/connection_pools.rb', line 54

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



58
59
60
# File 'lib/activerecord_partitioning/connection_pools.rb', line 58

def size
  @store.size
end

#valuesObject



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

def values
  @store.values
end