Class: ArchiveStorage::Configuration
- Inherits:
-
Object
- Object
- ArchiveStorage::Configuration
- Defined in:
- lib/archive_storage/configuration.rb
Instance Attribute Summary collapse
-
#default_batch_size ⇒ Object
Returns the value of attribute default_batch_size.
-
#default_cleanup_delay ⇒ Object
Returns the value of attribute default_cleanup_delay.
-
#delete_source_enabled ⇒ Object
Returns the value of attribute delete_source_enabled.
-
#enqueue_claim_ttl ⇒ Object
Returns the value of attribute enqueue_claim_ttl.
-
#fallback_on_read_errors ⇒ Object
Returns the value of attribute fallback_on_read_errors.
-
#job_backend ⇒ Object
Returns the value of attribute job_backend.
-
#migration_queue ⇒ Object
Returns the value of attribute migration_queue.
-
#mounts ⇒ Object
readonly
Returns the value of attribute mounts.
-
#registry_class_name ⇒ Object
Returns the value of attribute registry_class_name.
-
#schedule_queue ⇒ Object
Returns the value of attribute schedule_queue.
-
#schedules ⇒ Object
readonly
Returns the value of attribute schedules.
-
#storages ⇒ Object
readonly
Returns the value of attribute storages.
-
#verification_strategy ⇒ Object
Returns the value of attribute verification_strategy.
-
#verify_checksums ⇒ Object
Returns the value of attribute verify_checksums.
Instance Method Summary collapse
- #adapter(name) ⇒ Object
- #find_mount(model, mounted_as) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #mount(model, mounted_as, uploader: nil, policy: nil) ⇒ Object
- #registry_class ⇒ Object
- #schedule(name, cron:, model: nil, mounted_as: nil, uploader: nil, uploaders: nil, migration_rate: nil) ⇒ Object
- #storage(name, &block) ⇒ Object
- #storage!(name) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/archive_storage/configuration.rb', line 24 def initialize @storages = {} @mounts = [] @schedules = [] @adapter_cache = {} @migration_queue = :default @schedule_queue = :default @job_backend = :active_job @verification_strategy = :auto @verify_checksums = false @default_batch_size = 500 @default_cleanup_delay = 7 * 24 * 60 * 60 @enqueue_claim_ttl = 6 * 60 * 60 @delete_source_enabled = false @registry_class_name = "ArchiveStorage::Models::FileRecord" @fallback_on_read_errors = [NotFoundError] end |
Instance Attribute Details
#default_batch_size ⇒ Object
Returns the value of attribute default_batch_size.
10 11 12 |
# File 'lib/archive_storage/configuration.rb', line 10 def default_batch_size @default_batch_size end |
#default_cleanup_delay ⇒ Object
Returns the value of attribute default_cleanup_delay.
10 11 12 |
# File 'lib/archive_storage/configuration.rb', line 10 def default_cleanup_delay @default_cleanup_delay end |
#delete_source_enabled ⇒ Object
Returns the value of attribute delete_source_enabled.
10 11 12 |
# File 'lib/archive_storage/configuration.rb', line 10 def delete_source_enabled @delete_source_enabled end |
#enqueue_claim_ttl ⇒ Object
Returns the value of attribute enqueue_claim_ttl.
10 11 12 |
# File 'lib/archive_storage/configuration.rb', line 10 def enqueue_claim_ttl @enqueue_claim_ttl end |
#fallback_on_read_errors ⇒ Object
Returns the value of attribute fallback_on_read_errors.
10 11 12 |
# File 'lib/archive_storage/configuration.rb', line 10 def fallback_on_read_errors @fallback_on_read_errors end |
#job_backend ⇒ Object
Returns the value of attribute job_backend.
10 11 12 |
# File 'lib/archive_storage/configuration.rb', line 10 def job_backend @job_backend end |
#migration_queue ⇒ Object
Returns the value of attribute migration_queue.
10 11 12 |
# File 'lib/archive_storage/configuration.rb', line 10 def migration_queue @migration_queue end |
#mounts ⇒ Object (readonly)
Returns the value of attribute mounts.
22 23 24 |
# File 'lib/archive_storage/configuration.rb', line 22 def mounts @mounts end |
#registry_class_name ⇒ Object
Returns the value of attribute registry_class_name.
10 11 12 |
# File 'lib/archive_storage/configuration.rb', line 10 def registry_class_name @registry_class_name end |
#schedule_queue ⇒ Object
Returns the value of attribute schedule_queue.
10 11 12 |
# File 'lib/archive_storage/configuration.rb', line 10 def schedule_queue @schedule_queue end |
#schedules ⇒ Object (readonly)
Returns the value of attribute schedules.
22 23 24 |
# File 'lib/archive_storage/configuration.rb', line 22 def schedules @schedules end |
#storages ⇒ Object (readonly)
Returns the value of attribute storages.
22 23 24 |
# File 'lib/archive_storage/configuration.rb', line 22 def storages @storages end |
#verification_strategy ⇒ Object
Returns the value of attribute verification_strategy.
10 11 12 |
# File 'lib/archive_storage/configuration.rb', line 10 def verification_strategy @verification_strategy end |
#verify_checksums ⇒ Object
Returns the value of attribute verify_checksums.
21 22 23 |
# File 'lib/archive_storage/configuration.rb', line 21 def verify_checksums @verify_checksums end |
Instance Method Details
#adapter(name) ⇒ Object
60 61 62 |
# File 'lib/archive_storage/configuration.rb', line 60 def adapter(name) @adapter_cache[name.to_sym] ||= build_adapter(storage!(name)) end |
#find_mount(model, mounted_as) ⇒ Object
71 72 73 |
# File 'lib/archive_storage/configuration.rb', line 71 def find_mount(model, mounted_as) @mounts.find { |mount| mount.matches_model?(model, mounted_as) } end |
#mount(model, mounted_as, uploader: nil, policy: nil) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/archive_storage/configuration.rb', line 64 def mount(model, mounted_as, uploader: nil, policy: nil) MountConfig.new(model, mounted_as, uploader: uploader, policy: policy).tap do |mount| @mounts.reject! { |existing| existing.matches_model?(model, mounted_as) } @mounts << mount end end |
#registry_class ⇒ Object
89 90 91 92 93 |
# File 'lib/archive_storage/configuration.rb', line 89 def registry_class registry_class_name.to_s.split("::").inject(Object) do |namespace, const_name| namespace.const_get(const_name) end end |
#schedule(name, cron:, model: nil, mounted_as: nil, uploader: nil, uploaders: nil, migration_rate: nil) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/archive_storage/configuration.rb', line 75 def schedule(name, cron:, model: nil, mounted_as: nil, uploader: nil, uploaders: nil, migration_rate: nil) ScheduleConfig.new( name, cron: cron, model: model, mounted_as: mounted_as, uploaders: Array(uploaders || uploader), migration_rate: migration_rate ).tap do |schedule| schedule.validate! @schedules << schedule end end |
#storage(name, &block) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/archive_storage/configuration.rb', line 47 def storage(name, &block) config = (@storages[name.to_sym] ||= StorageConfig.new(name)) block.call(config) if block @adapter_cache.delete(name.to_sym) config end |
#storage!(name) ⇒ Object
54 55 56 57 58 |
# File 'lib/archive_storage/configuration.rb', line 54 def storage!(name) @storages.fetch(name.to_sym) do raise ConfigurationError, "unknown archive storage #{name.inspect}" end end |