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.
-
#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
- #eligible?(record, now:, timestamp_attribute:) ⇒ Boolean
-
#initialize(role, storage_key, after: nil, condition: nil, scope: nil) ⇒ StorageRule
constructor
A new instance of StorageRule.
- #scoped? ⇒ Boolean
Constructor Details
#initialize(role, storage_key, after: nil, condition: nil, scope: nil) ⇒ StorageRule
Returns a new instance of StorageRule.
7 8 9 10 11 12 13 |
# File 'lib/archive_storage/storage_rule.rb', line 7 def initialize(role, storage_key, after: nil, condition: nil, scope: nil) @role = role.to_sym @storage_key = storage_key.to_sym @after = after @condition = condition @scope = scope 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 |
#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
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/archive_storage/storage_rule.rb', line 24 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 |
#eligible?(record, now:, timestamp_attribute:) ⇒ Boolean
15 16 17 18 |
# File 'lib/archive_storage/storage_rule.rb', line 15 def eligible?(record, now:, timestamp_attribute:) old_enough?(record, now: now, timestamp_attribute: ) && condition_matches?(record) end |
#scoped? ⇒ Boolean
20 21 22 |
# File 'lib/archive_storage/storage_rule.rb', line 20 def scoped? !scope.nil? end |