Class: ArchiveStorage::Policy

Inherits:
Object
  • Object
show all
Defined in:
lib/archive_storage/policy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePolicy

Returns a new instance of Policy.



16
17
18
19
20
21
22
23
24
# File 'lib/archive_storage/policy.rb', line 16

def initialize
  @rules = []
  @read_fallbacks = []
  @delete_source_delay = nil
  @delete_requires_verification = true
  @include_versions = false
  @selected_versions = nil
  @timestamp_attribute = :created_at
end

Instance Attribute Details

#delete_requires_verificationObject

Returns the value of attribute delete_requires_verification.



7
8
9
# File 'lib/archive_storage/policy.rb', line 7

def delete_requires_verification
  @delete_requires_verification
end

#delete_source_delayObject

Returns the value of attribute delete_source_delay.



7
8
9
# File 'lib/archive_storage/policy.rb', line 7

def delete_source_delay
  @delete_source_delay
end

#include_versionsObject

Returns the value of attribute include_versions.



7
8
9
# File 'lib/archive_storage/policy.rb', line 7

def include_versions
  @include_versions
end

#primary_storageObject

Returns the value of attribute primary_storage.



7
8
9
# File 'lib/archive_storage/policy.rb', line 7

def primary_storage
  @primary_storage
end

#read_fallbacksObject

Returns the value of attribute read_fallbacks.



7
8
9
# File 'lib/archive_storage/policy.rb', line 7

def read_fallbacks
  @read_fallbacks
end

#rulesObject

Returns the value of attribute rules.



7
8
9
# File 'lib/archive_storage/policy.rb', line 7

def rules
  @rules
end

#selected_versionsObject

Returns the value of attribute selected_versions.



7
8
9
# File 'lib/archive_storage/policy.rb', line 7

def selected_versions
  @selected_versions
end

#timestamp_attributeObject

Returns the value of attribute timestamp_attribute.



7
8
9
# File 'lib/archive_storage/policy.rb', line 7

def timestamp_attribute
  @timestamp_attribute
end

Instance Method Details

#apply_rule_scopes(scope) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/archive_storage/policy.rb', line 38

def apply_rule_scopes(scope)
  scoped_rules = rules.select(&:scoped?)
  return scope if scoped_rules.empty?

  relations = scoped_rules.map { |rule| rule.apply_scope(scope) }
  relations.reduce do |combined, relation|
    combined.respond_to?(:or) ? combined.or(relation) : combined
  end
end

#primary_storage_keyObject



26
27
28
# File 'lib/archive_storage/policy.rb', line 26

def primary_storage_key
  primary_storage&.storage_key
end

#target_storage_for(record, now: Time.now) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/archive_storage/policy.rb', line 30

def target_storage_for(record, now: Time.now)
  eligible_rules = rules.select do |rule|
    rule.eligible?(record, now: now, timestamp_attribute: timestamp_attribute)
  end

  eligible_rules.last&.storage_key
end