Class: ActiveRecord::Sharding::ShardRepository
- Inherits:
-
AbstractRepository
- Object
- AbstractRepository
- ActiveRecord::Sharding::ShardRepository
- Defined in:
- lib/active_record/sharding/shard_repository.rb
Instance Attribute Summary collapse
-
#base_class ⇒ Object
readonly
Returns the value of attribute base_class.
Instance Method Summary collapse
- #all ⇒ Object
- #fetch(connection_name) ⇒ Object
-
#initialize(cluster_config, base_class) ⇒ ShardRepository
constructor
A new instance of ShardRepository.
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_class ⇒ Object (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
#all ⇒ Object
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 |