Class: DbBlaster::Finder
- Inherits:
-
Object
- Object
- DbBlaster::Finder
- Includes:
- AvailableTables
- Defined in:
- lib/db_blaster/finder.rb
Overview
Find records and yield them a ‘batch_size` at a time
Constant Summary
Constants included from AvailableTables
AvailableTables::SYSTEM_TABLES
Instance Attribute Summary collapse
-
#block_on_find ⇒ Object
readonly
Returns the value of attribute block_on_find.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#source_table ⇒ Object
readonly
Returns the value of attribute source_table.
Class Method Summary collapse
Instance Method Summary collapse
- #find ⇒ Object
-
#initialize(source_table, &block) ⇒ Finder
constructor
A new instance of Finder.
Methods included from AvailableTables
Constructor Details
#initialize(source_table, &block) ⇒ Finder
Returns a new instance of Finder.
9 10 11 12 13 |
# File 'lib/db_blaster/finder.rb', line 9 def initialize(source_table, &block) @source_table = source_table @block_on_find = block @offset = 0 end |
Instance Attribute Details
#block_on_find ⇒ Object (readonly)
Returns the value of attribute block_on_find.
7 8 9 |
# File 'lib/db_blaster/finder.rb', line 7 def block_on_find @block_on_find end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
7 8 9 |
# File 'lib/db_blaster/finder.rb', line 7 def offset @offset end |
#source_table ⇒ Object (readonly)
Returns the value of attribute source_table.
7 8 9 |
# File 'lib/db_blaster/finder.rb', line 7 def source_table @source_table end |
Class Method Details
.find(source_table, &block) ⇒ Object
17 18 19 |
# File 'lib/db_blaster/finder.rb', line 17 def self.find(source_table, &block) new(source_table, &block).find end |
Instance Method Details
#find ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/db_blaster/finder.rb', line 21 def find verify_source_table_name find_records_in_batches do |batch| filtered = batch.collect(&method(:filter_columns)) next if filtered.blank? Chunker.chunk(source_table, filtered) do |chunked| block_on_find.call(chunked) end end end |