Class: ArchiveStorage::Policy
- Inherits:
-
Object
- Object
- ArchiveStorage::Policy
- Defined in:
- lib/archive_storage/policy.rb
Instance Attribute Summary collapse
-
#delete_requires_verification ⇒ Object
Returns the value of attribute delete_requires_verification.
-
#delete_source_delay ⇒ Object
Returns the value of attribute delete_source_delay.
-
#include_versions ⇒ Object
Returns the value of attribute include_versions.
-
#primary_storage ⇒ Object
Returns the value of attribute primary_storage.
-
#read_fallbacks ⇒ Object
Returns the value of attribute read_fallbacks.
-
#rules ⇒ Object
Returns the value of attribute rules.
-
#selected_versions ⇒ Object
Returns the value of attribute selected_versions.
-
#timestamp_attribute ⇒ Object
Returns the value of attribute timestamp_attribute.
Instance Method Summary collapse
- #apply_rule_scopes(scope) ⇒ Object
-
#initialize ⇒ Policy
constructor
A new instance of Policy.
- #primary_storage_key ⇒ Object
- #target_storage_for(record, now: Time.now) ⇒ Object
Constructor Details
#initialize ⇒ Policy
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_verification ⇒ Object
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_delay ⇒ Object
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_versions ⇒ Object
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_storage ⇒ Object
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_fallbacks ⇒ Object
Returns the value of attribute read_fallbacks.
7 8 9 |
# File 'lib/archive_storage/policy.rb', line 7 def read_fallbacks @read_fallbacks end |
#rules ⇒ Object
Returns the value of attribute rules.
7 8 9 |
# File 'lib/archive_storage/policy.rb', line 7 def rules @rules end |
#selected_versions ⇒ Object
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_attribute ⇒ Object
Returns the value of attribute timestamp_attribute.
7 8 9 |
# File 'lib/archive_storage/policy.rb', line 7 def @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_key ⇒ Object
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: ) end eligible_rules.last&.storage_key end |