Class: ArchiveStorage::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/archive_storage/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_sizeObject

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_delayObject

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_enabledObject

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_ttlObject

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_errorsObject

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_backendObject

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_queueObject

Returns the value of attribute migration_queue.



10
11
12
# File 'lib/archive_storage/configuration.rb', line 10

def migration_queue
  @migration_queue
end

#mountsObject (readonly)

Returns the value of attribute mounts.



22
23
24
# File 'lib/archive_storage/configuration.rb', line 22

def mounts
  @mounts
end

#registry_class_nameObject

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_queueObject

Returns the value of attribute schedule_queue.



10
11
12
# File 'lib/archive_storage/configuration.rb', line 10

def schedule_queue
  @schedule_queue
end

#schedulesObject (readonly)

Returns the value of attribute schedules.



22
23
24
# File 'lib/archive_storage/configuration.rb', line 22

def schedules
  @schedules
end

#storagesObject (readonly)

Returns the value of attribute storages.



22
23
24
# File 'lib/archive_storage/configuration.rb', line 22

def storages
  @storages
end

#verification_strategyObject

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_checksumsObject

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_classObject



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