Class: ArchiveStorage::PolicyBuilder
- Inherits:
-
Object
- Object
- ArchiveStorage::PolicyBuilder
- Defined in:
- lib/archive_storage/policy_builder.rb
Instance Attribute Summary collapse
-
#policy ⇒ Object
readonly
Returns the value of attribute policy.
Class Method Summary collapse
Instance Method Summary collapse
- #archive(name, **options) ⇒ Object
- #delete_source_after(verification: true, delay:) ⇒ Object
- #include_versions(value = true) ⇒ Object
-
#initialize ⇒ PolicyBuilder
constructor
A new instance of PolicyBuilder.
- #primary(name) ⇒ Object (also: #hot)
- #read_fallbacks(*names) ⇒ Object
- #rule(role, name, **options) ⇒ Object
- #storage(name, **options) ⇒ Object
- #timestamp_attribute(name) ⇒ Object
- #validate! ⇒ Object
- #versions(*names) ⇒ Object
- #warm(name, **options) ⇒ Object
Constructor Details
#initialize ⇒ PolicyBuilder
Returns a new instance of PolicyBuilder.
15 16 17 |
# File 'lib/archive_storage/policy_builder.rb', line 15 def initialize @policy = Policy.new end |
Instance Attribute Details
#policy ⇒ Object (readonly)
Returns the value of attribute policy.
13 14 15 |
# File 'lib/archive_storage/policy_builder.rb', line 13 def policy @policy end |
Class Method Details
.build(&block) ⇒ Object
9 10 11 |
# File 'lib/archive_storage/policy_builder.rb', line 9 def self.build(&block) new.tap { |builder| builder.instance_eval(&block) }.tap(&:validate!).policy end |
Instance Method Details
#archive(name, **options) ⇒ Object
33 34 35 |
# File 'lib/archive_storage/policy_builder.rb', line 33 def archive(name, **) rule(:archive, name, **) end |
#delete_source_after(verification: true, delay:) ⇒ Object
55 56 57 58 |
# File 'lib/archive_storage/policy_builder.rb', line 55 def delete_source_after(verification: true, delay:) policy.delete_requires_verification = verification policy.delete_source_delay = delay end |
#include_versions(value = true) ⇒ Object
60 61 62 |
# File 'lib/archive_storage/policy_builder.rb', line 60 def include_versions(value = true) policy.include_versions = value end |
#primary(name) ⇒ Object Also known as: hot
23 24 25 |
# File 'lib/archive_storage/policy_builder.rb', line 23 def primary(name) policy.primary_storage = StorageRule.new(:primary, name) end |
#read_fallbacks(*names) ⇒ Object
51 52 53 |
# File 'lib/archive_storage/policy_builder.rb', line 51 def read_fallbacks(*names) policy.read_fallbacks = names.flatten.compact.map(&:to_sym) end |
#rule(role, name, **options) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/archive_storage/policy_builder.rb', line 41 def rule(role, name, **) policy.rules << StorageRule.new( role, name, after: [:after], condition: [:if], scope: [:scope] ) end |
#storage(name, **options) ⇒ Object
37 38 39 |
# File 'lib/archive_storage/policy_builder.rb', line 37 def storage(name, **) rule(:storage, name, **) end |
#timestamp_attribute(name) ⇒ Object
68 69 70 |
# File 'lib/archive_storage/policy_builder.rb', line 68 def (name) policy. = name.to_sym end |
#validate! ⇒ Object
19 20 21 |
# File 'lib/archive_storage/policy_builder.rb', line 19 def validate! raise ConfigurationError, "archive_storage requires a primary storage" unless policy.primary_storage_key end |
#versions(*names) ⇒ Object
64 65 66 |
# File 'lib/archive_storage/policy_builder.rb', line 64 def versions(*names) policy.selected_versions = names.flatten.compact.map(&:to_sym) end |
#warm(name, **options) ⇒ Object
29 30 31 |
# File 'lib/archive_storage/policy_builder.rb', line 29 def warm(name, **) rule(:warm, name, **) end |