Class: ArchiveStorage::Storage

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uploader) ⇒ Storage

Returns a new instance of Storage.



9
10
11
# File 'lib/archive_storage/storage.rb', line 9

def initialize(uploader)
  @uploader = uploader
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



7
8
9
# File 'lib/archive_storage/storage.rb', line 7

def identifier
  @identifier
end

#uploaderObject (readonly)

Returns the value of attribute uploader.



7
8
9
# File 'lib/archive_storage/storage.rb', line 7

def uploader
  @uploader
end

Instance Method Details

#cache!(new_file) ⇒ Object



47
48
49
# File 'lib/archive_storage/storage.rb', line 47

def cache!(new_file)
  file_cache_storage.cache!(new_file)
end

#clean_cache!(seconds) ⇒ Object



59
60
61
# File 'lib/archive_storage/storage.rb', line 59

def clean_cache!(seconds)
  file_cache_storage.clean_cache!(seconds)
end

#delete_dir!(path) ⇒ Object



55
56
57
# File 'lib/archive_storage/storage.rb', line 55

def delete_dir!(path)
  file_cache_storage.delete_dir!(path)
end

#retrieve!(identifier) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/archive_storage/storage.rb', line 38

def retrieve!(identifier)
  @identifier = identifier
  StoredFile.new(
    uploader,
    identifier,
    storage_key: uploader.store_path(identifier)
  )
end

#retrieve_from_cache!(identifier) ⇒ Object



51
52
53
# File 'lib/archive_storage/storage.rb', line 51

def retrieve_from_cache!(identifier)
  file_cache_storage.retrieve_from_cache!(identifier)
end

#store!(file) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/archive_storage/storage.rb', line 13

def store!(file)
  identifier = identifier_for(file)
  @identifier = identifier
  storage_key = uploader.store_path(identifier)
  primary_storage = policy.primary_storage_key
  adapter = ArchiveStorage.adapter(primary_storage)

  adapter.upload(storage_key, file)
   = safe_head(adapter, storage_key)

  ArchiveStorage.registry.upsert_for_uploader(
    uploader,
    identifier: identifier,
    storage_key: storage_key,
    current_storage: primary_storage,
    metadata: {
      byte_size: &.byte_size,
      content_type: &.content_type,
      checksum: &.etag
    }
  )

  StoredFile.new(uploader, identifier, storage_key: storage_key)
end