Class: ActiveRecord::Sharding::ShardRepository

Inherits:
AbstractRepository show all
Defined in:
lib/active_record/sharding/shard_repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cluster_config, base_class) ⇒ ShardRepository

Returns a new instance of ShardRepository.



6
7
8
9
10
11
12
13
14
# File 'lib/active_record/sharding/shard_repository.rb', line 6

def initialize(cluster_config, base_class)
  @base_class = base_class

  shards = cluster_config.connections.map do |connection_name|
    [connection_name, generate_model_for_shard(connection_name)]
  end

  @shards = Hash[shards]
end

Instance Attribute Details

#base_classObject (readonly)

Returns the value of attribute base_class.



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

def base_class
  @base_class
end

Instance Method Details

#allObject



20
21
22
# File 'lib/active_record/sharding/shard_repository.rb', line 20

def all
  @shards.values
end

#fetch(connection_name) ⇒ Object



16
17
18
# File 'lib/active_record/sharding/shard_repository.rb', line 16

def fetch(connection_name)
  @shards.fetch connection_name
end