Class: ArchiveStorage::StorageRule
- Inherits:
-
Object
- Object
- ArchiveStorage::StorageRule
- Defined in:
- lib/archive_storage/storage_rule.rb
Instance Attribute Summary collapse
-
#after ⇒ Object
readonly
Returns the value of attribute after.
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#max_byte_size ⇒ Object
readonly
Returns the value of attribute max_byte_size.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#storage_key ⇒ Object
readonly
Returns the value of attribute storage_key.
Instance Method Summary collapse
- #apply_scope(relation) ⇒ Object
- #byte_size_allowed?(byte_size) ⇒ Boolean
- #eligible?(record, now:, timestamp_attribute:, byte_size: nil) ⇒ Boolean
-
#initialize(role, storage_key, after: nil, condition: nil, scope: nil, max_byte_size: nil) ⇒ StorageRule
constructor
A new instance of StorageRule.
- #max_byte_size? ⇒ Boolean
- #requires_byte_size_for?(record, now:, timestamp_attribute:) ⇒ Boolean
- #scoped? ⇒ Boolean
Constructor Details
#initialize(role, storage_key, after: nil, condition: nil, scope: nil, max_byte_size: nil) ⇒ StorageRule
Returns a new instance of StorageRule.
7 8 9 10 11 12 13 14 |
# File 'lib/archive_storage/storage_rule.rb', line 7 def initialize(role, storage_key, after: nil, condition: nil, scope: nil, max_byte_size: nil) @role = role.to_sym @storage_key = storage_key.to_sym @after = after @condition = condition @scope = scope @max_byte_size = normalize_byte_size(max_byte_size) end |
Instance Attribute Details
#after ⇒ Object (readonly)
Returns the value of attribute after.
5 6 7 |
# File 'lib/archive_storage/storage_rule.rb', line 5 def after @after end |
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
5 6 7 |
# File 'lib/archive_storage/storage_rule.rb', line 5 def condition @condition end |
#max_byte_size ⇒ Object (readonly)
Returns the value of attribute max_byte_size.
5 6 7 |
# File 'lib/archive_storage/storage_rule.rb', line 5 def max_byte_size @max_byte_size end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
5 6 7 |
# File 'lib/archive_storage/storage_rule.rb', line 5 def role @role end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
5 6 7 |
# File 'lib/archive_storage/storage_rule.rb', line 5 def scope @scope end |
#storage_key ⇒ Object (readonly)
Returns the value of attribute storage_key.
5 6 7 |
# File 'lib/archive_storage/storage_rule.rb', line 5 def storage_key @storage_key end |
Instance Method Details
#apply_scope(relation) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/archive_storage/storage_rule.rb', line 26 def apply_scope(relation) case scope when Symbol, String relation.public_send(scope) when Proc scope.arity.zero? ? relation.instance_exec(&scope) : scope.call(relation) else relation.respond_to?(:merge) ? relation.merge(scope) : scope end end |
#byte_size_allowed?(byte_size) ⇒ Boolean
47 48 49 50 51 52 |
# File 'lib/archive_storage/storage_rule.rb', line 47 def byte_size_allowed?(byte_size) return true unless max_byte_size? return false if byte_size.nil? byte_size <= max_byte_size end |
#eligible?(record, now:, timestamp_attribute:, byte_size: nil) ⇒ Boolean
16 17 18 19 20 |
# File 'lib/archive_storage/storage_rule.rb', line 16 def eligible?(record, now:, timestamp_attribute:, byte_size: nil) old_enough?(record, now: now, timestamp_attribute: ) && condition_matches?(record) && byte_size_allowed?(byte_size) end |
#max_byte_size? ⇒ Boolean
37 38 39 |
# File 'lib/archive_storage/storage_rule.rb', line 37 def max_byte_size? !max_byte_size.nil? end |
#requires_byte_size_for?(record, now:, timestamp_attribute:) ⇒ Boolean
41 42 43 44 45 |
# File 'lib/archive_storage/storage_rule.rb', line 41 def requires_byte_size_for?(record, now:, timestamp_attribute:) max_byte_size? && old_enough?(record, now: now, timestamp_attribute: ) && condition_matches?(record) end |
#scoped? ⇒ Boolean
22 23 24 |
# File 'lib/archive_storage/storage_rule.rb', line 22 def scoped? !scope.nil? end |