Class: Longleaf::FilesystemMetadataLocation

Inherits:
MetadataLocation show all
Defined in:
lib/longleaf/models/filesystem_metadata_location.rb

Overview

A filesystem based location in which metadata associated with registered files is stored.

Instance Attribute Summary

Attributes inherited from MetadataLocation

#digests, #path

Instance Method Summary collapse

Methods inherited from MetadataLocation

#contains?, #relative_file_path_for

Constructor Details

#initialize(config) ⇒ FilesystemMetadataLocation

Returns a new instance of FilesystemMetadataLocation.



10
11
12
# File 'lib/longleaf/models/filesystem_metadata_location.rb', line 10

def initialize(config)
  super(config)
end

Instance Method Details

#available?Boolean

Checks that the path defined in this metadata location are available

Returns:

  • (Boolean)

Raises:



51
52
53
54
# File 'lib/longleaf/models/filesystem_metadata_location.rb', line 51

def available?
  raise StorageLocationUnavailableError.new("Metadata path does not exist or is not a directory: #{@path}")\
      unless Dir.exist?(@path)
end

#metadata_path_for(file_path) ⇒ Object

Get the absolute path for the metadata file for the given file path located in this storage location.

Parameters:

  • file_path (String)

    path of the file relative its storage location

Returns:

  • absolute path to the metadata

Raises:

  • (ArgumentError)

    if the file_path is not provided.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/longleaf/models/filesystem_metadata_location.rb', line 23

def (file_path)
  raise ArgumentError.new("A file_path parameter is required") if file_path.nil?
  raise ArgumentError.new("File path must be relative") if Pathname.new(file_path).absolute?

  md_path = File.join(@path, file_path)
  # If the file_path is to a file, then add metadata suffix.
  if md_path.end_with?('/')
    md_path
  else
    md_path + MetadataSerializer::
  end
end

#relativize(md_path) ⇒ Object

Get the metadata path relative to this location

Parameters:

  • md_path (String)

    metadata file path

Returns:

  • the metadata path relative to this location

Raises:

  • (ArgumentError)

    if the metadata path is not contained by this location



40
41
42
43
44
45
46
# File 'lib/longleaf/models/filesystem_metadata_location.rb', line 40

def relativize(md_path)
  return md_path if Pathname.new(md_path).relative?

  raise ArgumentError.new("Metadata path must be contained by this location") if !md_path.start_with?(@path)

  md_path.sub(@path, "")
end

#typeObject

Returns the storage type for this location.

Returns:

  • the storage type for this location



15
16
17
# File 'lib/longleaf/models/filesystem_metadata_location.rb', line 15

def type
  StorageTypes::FILESYSTEM_STORAGE_TYPE
end