class EtFakeCcd::DocumentStoreService::InMemoryAdapter

Attributes

data[RW]
file_storage_path[RW]

Public Class Methods

new(file_storage_path: ::EtFakeCcd.config.file_storage_path) click to toggle source
# 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

Public Instance Methods

fetch_by_id(id) click to toggle source
# File lib/et_fake_ccd/document_store_service.rb, line 54
def fetch_by_id(id)
  data[id]
end
fetch_file_by_id(id) click to toggle source
# 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:) click to toggle source
# 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