Class: EtFakeCcd::DocumentStoreService::InMemoryAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/et_fake_ccd/document_store_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_storage_path: ::EtFakeCcd.config.file_storage_path) ⇒ InMemoryAdapter

Returns a new instance of InMemoryAdapter.



35
36
37
38
# File 'lib/et_fake_ccd/document_store_service.rb', line 35

def initialize(file_storage_path: ::EtFakeCcd.config.file_storage_path)
  self.data = {}
  self.file_storage_path = file_storage_path
end

Instance Method Details

#fetch_by_id(id) ⇒ Object



54
55
56
# File 'lib/et_fake_ccd/document_store_service.rb', line 54

def fetch_by_id(id)
  data[id]
end

#fetch_file_by_id(id) ⇒ Object



58
59
60
61
62
63
# File 'lib/et_fake_ccd/document_store_service.rb', line 58

def fetch_file_by_id(id)
  document = fetch_by_id(id)
  return nil if document.nil?

  File.new(File.join(file_storage_path, document['file_path']), 'rb')
end

#store(filename:, type:, file:, classification:) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/et_fake_ccd/document_store_service.rb', line 40

def store(filename:, type:, file:, classification:)
  uuid = SecureRandom.uuid
  file_path = File.join(file_storage_path, uuid)
  FileUtils.cp file.path, file_path
  data[uuid] = {
    'filename' => filename,
    'type' => type,
    'file_path' => uuid,
    'size' => file.size,
    'classification' => classification
  }
  uuid
end