Class: Tartarus::ArchivableItem

Inherits:
Object
  • Object
show all
Defined in:
lib/tartarus/archivable_item.rb,
lib/tartarus/archivable_item/sidekiq_cron_job_serializer.rb

Defined Under Namespace

Classes: SidekiqCronJobSerializer

Constant Summary collapse

REQUIRED_ATTRIBUTES_NAMES =
%i(model cron queue archive_items_older_than timestamp_field active_job
archive_with tenant_value_source).freeze
OPTIONAL_ATTRIBUTES_NAMES =
%i(tenants_range tenant_id_field batch_size remote_storage name).freeze

Instance Method Summary collapse

Instance Method Details

#active_jobObject



38
39
40
# File 'lib/tartarus/archivable_item.rb', line 38

def active_job
  @active_job || false
end

#archive_items_older_than=(value) ⇒ Object



14
15
16
17
18
# File 'lib/tartarus/archivable_item.rb', line 14

def archive_items_older_than=(value)
  raise ":archive_items_older_than must be a lambda" if !value.respond_to?(:call)

  @archive_items_older_than = value
end

#archive_strategy(factory: Tartarus::ArchiveStrategy.new) ⇒ Object



66
67
68
# File 'lib/tartarus/archivable_item.rb', line 66

def archive_strategy(factory: Tartarus::ArchiveStrategy.new)
  factory.for(archive_with, batch_size: batch_size)
end

#archive_withObject



42
43
44
45
46
# File 'lib/tartarus/archivable_item.rb', line 42

def archive_with
  return @archive_with if defined?(@archive_with)

  @archive_with ||= :delete_all
end

#batch_sizeObject



48
49
50
51
52
# File 'lib/tartarus/archivable_item.rb', line 48

def batch_size
  return @batch_size if defined?(@batch_size)

  @batch_size ||= 10_000
end

#cron=(value) ⇒ Object



8
9
10
11
12
# File 'lib/tartarus/archivable_item.rb', line 8

def cron=(value)
  Fugit.do_parse_cron(value)

  @cron = value
end

#nameObject



54
55
56
# File 'lib/tartarus/archivable_item.rb', line 54

def name
  @name || @model.to_s
end

#remote_storageObject



70
71
72
# File 'lib/tartarus/archivable_item.rb', line 70

def remote_storage
  @remote_storage || Tartarus::RemoteStorage::Null
end

#scope_by_tenant?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/tartarus/archivable_item.rb', line 62

def scope_by_tenant?
  !!tenant_id_field
end

#tenant_value_sourceObject



32
33
34
35
36
# File 'lib/tartarus/archivable_item.rb', line 32

def tenant_value_source
  return @tenant_value_source if defined?(@tenant_value_source)

  @tenant_value_source ||= :id
end

#tenants_rangeObject



26
27
28
29
30
# File 'lib/tartarus/archivable_item.rb', line 26

def tenants_range
  return @tenants_range if defined?(@tenants_range)

  @tenants_range ||= -> { [] }
end

#tenants_range=(value) ⇒ Object



20
21
22
23
24
# File 'lib/tartarus/archivable_item.rb', line 20

def tenants_range=(value)
  raise ":tenants_range must be a lambda" if !value.respond_to?(:call)

  @tenants_range = value
end

#validate!Object



58
59
60
# File 'lib/tartarus/archivable_item.rb', line 58

def validate!
  validate_presence
end