Class: ActiveRecord::Sharding::AllShardsInParallel

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/sharding/all_shards_in_parallel.rb

Instance Method Summary collapse

Constructor Details

#initialize(shards) ⇒ AllShardsInParallel

Returns a new instance of AllShardsInParallel.



7
8
9
# File 'lib/active_record/sharding/all_shards_in_parallel.rb', line 7

def initialize(shards)
  @shards = shards
end

Instance Method Details

#each(&block) ⇒ Object



23
24
25
26
# File 'lib/active_record/sharding/all_shards_in_parallel.rb', line 23

def each(&block)
  map(&block) if block_given?
  self
end

#flat_map(&block) ⇒ Object



19
20
21
# File 'lib/active_record/sharding/all_shards_in_parallel.rb', line 19

def flat_map(&block)
  map(&block).flatten
end

#map(&_block) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/active_record/sharding/all_shards_in_parallel.rb', line 11

def map(&_block)
  commands = @shards.map do |model|
    Expeditor::Command.new { model.connection_pool.with_connection { yield model } }
  end
  commands.each(&:start)
  commands.map(&:get)
end