Class: ActiverecordHoarder::BatchArchiver

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord_hoarder/batch_archiver.rb

Instance Method Summary collapse

Constructor Details

#initialize(model_class, storage = nil) ⇒ BatchArchiver

Returns a new instance of BatchArchiver.



2
3
4
5
# File 'lib/activerecord_hoarder/batch_archiver.rb', line 2

def initialize(model_class, storage = nil)
  @record_collector = ::ActiverecordHoarder::RecordCollector.new(model_class)
  @archive_storage = storage || default_storage_for_records(model_class.table_name)
end

Instance Method Details

#archive_batchObject



7
8
9
10
11
12
# File 'lib/activerecord_hoarder/batch_archiver.rb', line 7

def archive_batch
  @record_collector.in_batches(delete_on_success: true) do |batch|
    success = @archive_storage.store_data(batch)
    return if !success
  end
end

#default_storage_for_records(table_name) ⇒ Object



14
15
16
# File 'lib/activerecord_hoarder/batch_archiver.rb', line 14

def default_storage_for_records(table_name)
  ::ActiverecordHoarder::Storage.new(table_name)
end