Class: ActiveRecord::ShardFor::STIShardRepository

Inherits:
AbstractShardRepository show all
Defined in:
lib/activerecord/shard_for/sti_shard_repository.rb

Instance Attribute Summary collapse

Attributes inherited from AbstractShardRepository

#shards

Instance Method Summary collapse

Methods inherited from AbstractShardRepository

#all, #fetch, #fetch_by_key

Constructor Details

#initialize(inherited_class, base_shards) ⇒ STIShardRepository

Returns a new instance of STIShardRepository.

Parameters:

  • A (Class)

    sub class of AR model.



8
9
10
11
12
13
14
15
16
# File 'lib/activerecord/shard_for/sti_shard_repository.rb', line 8

def initialize(inherited_class, base_shards)
  @inherited_class = inherited_class

  @shards = base_shards.each_with_object({}) do |(connection_name, base_model), hash|
    model = generate_model_from_shard(connection_name, base_model)
    inherited_class.const_set(:"#{generate_shard_name(connection_name)}", model)
    hash[connection_name] = model
  end
end

Instance Attribute Details

#inherited_classObject (readonly)

Returns the value of attribute inherited_class.



4
5
6
# File 'lib/activerecord/shard_for/sti_shard_repository.rb', line 4

def inherited_class
  @inherited_class
end