Class: Tartarus::ArchiveStrategy::ExtractBatch
- Inherits:
-
Object
- Object
- Tartarus::ArchiveStrategy::ExtractBatch
- Defined in:
- lib/tartarus/archive_strategy/extract_batch.rb
Instance Method Summary collapse
- #call(collection) ⇒ Object
-
#initialize(config: Thread.current) ⇒ ExtractBatch
constructor
A new instance of ExtractBatch.
- #suppressed_in_batches? ⇒ Boolean
Constructor Details
#initialize(config: Thread.current) ⇒ ExtractBatch
Returns a new instance of ExtractBatch.
7 8 9 |
# File 'lib/tartarus/archive_strategy/extract_batch.rb', line 7 def initialize(config: Thread.current) @config = config end |
Instance Method Details
#call(collection) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/tartarus/archive_strategy/extract_batch.rb', line 11 def call(collection) if collection.respond_to?(:in_batches) && !suppressed_in_batches? yield collection.in_batches else primary_key = collection.primary_key collection.select(primary_key).find_in_batches do |group| yield collection.where(primary_key => group) end end end |
#suppressed_in_batches? ⇒ Boolean
23 24 25 |
# File 'lib/tartarus/archive_strategy/extract_batch.rb', line 23 def suppressed_in_batches? !!config["__TARTARUS__SUPPRESSED_IN_BATCHES"] end |