Class: Lhm::ChunkFinder
- Inherits:
-
Object
- Object
- Lhm::ChunkFinder
- Defined in:
- lib/lhm/chunk_finder.rb
Constant Summary collapse
- LOG_PREFIX =
"Chunker"
Instance Method Summary collapse
- #each_chunk ⇒ Object
-
#initialize(migration, connection = nil, options = {}) ⇒ ChunkFinder
constructor
A new instance of ChunkFinder.
- #max_rows ⇒ Object
- #processed_rows ⇒ Object
- #table_empty? ⇒ Boolean
- #validate ⇒ Object
Constructor Details
#initialize(migration, connection = nil, options = {}) ⇒ ChunkFinder
Returns a new instance of ChunkFinder.
5 6 7 8 9 10 11 12 |
# File 'lib/lhm/chunk_finder.rb', line 5 def initialize(migration, connection = nil, = {}) @migration = migration @connection = connection @start = [:start] || select_start_from_db @limit = [:limit] || select_limit_from_db @throttler = [:throttler] @processed_rows = 0 end |
Instance Method Details
#each_chunk ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/lhm/chunk_finder.rb', line 24 def each_chunk next_id = @start @processed_rows = 0 while next_id <= @limit top = upper_id(next_id) @processed_rows += @throttler.stride yield ChunkInsert.new(@migration, @connection, next_id, top) next_id = top + 1 end end |
#max_rows ⇒ Object
35 36 37 |
# File 'lib/lhm/chunk_finder.rb', line 35 def max_rows @limit - @start + 1 end |
#processed_rows ⇒ Object
39 40 41 |
# File 'lib/lhm/chunk_finder.rb', line 39 def processed_rows @processed_rows end |
#table_empty? ⇒ Boolean
14 15 16 |
# File 'lib/lhm/chunk_finder.rb', line 14 def table_empty? start.nil? && limit.nil? end |
#validate ⇒ Object
18 19 20 21 22 |
# File 'lib/lhm/chunk_finder.rb', line 18 def validate if start > limit raise ArgumentError, "impossible chunk options (limit (#{limit.inspect} must be greater than start (#{start.inspect})" end end |