Class: Longleaf::MetadataPersistenceManager

Inherits:
Object
  • Object
show all
Defined in:
lib/longleaf/services/metadata_persistence_manager.rb

Overview

Handles the persistence of metadata records

Instance Method Summary collapse

Constructor Details

#initialize(index_manager) ⇒ MetadataPersistenceManager

Initialize the MetadataPersistenceManager

Parameters:



9
10
11
# File 'lib/longleaf/services/metadata_persistence_manager.rb', line 9

def initialize(index_manager)
  @index_manager = index_manager
end

Instance Method Details

#index(file_rec) ⇒ Object

Index metadata for the provided file record

Parameters:



30
31
32
33
34
# File 'lib/longleaf/services/metadata_persistence_manager.rb', line 30

def index(file_rec)
  if @index_manager.using_index?
    @index_manager.index(file_rec)
  end
end

#load(file_rec) ⇒ MetadataRecord

Load the metadata record for the provided file record

Parameters:

Returns:



39
40
41
42
43
44
# File 'lib/longleaf/services/metadata_persistence_manager.rb', line 39

def load(file_rec)
  md_rec = MetadataDeserializer.deserialize(file_path: file_rec.,
              digest_algs: file_rec.storage_location.)
  file_rec. = md_rec
  md_rec
end

#persist(file_rec) ⇒ Object

Persist the metadata for the provided file record to all configured destinations. This may include to disk as well as to an index.

Parameters:



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/longleaf/services/metadata_persistence_manager.rb', line 16

def persist(file_rec)
  if file_rec..nil?
    raise MetadataError.new("No metadata record provided, cannot persist metadata for #{file_rec.path}")
  end

  MetadataSerializer::write(metadata: file_rec.,
      file_path: file_rec.,
      digest_algs: file_rec.storage_location.)

  index(file_rec)
end