class Longleaf::FilesystemMetadataLocation

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

Public Class Methods

new(config) click to toggle source
Calls superclass method
# File lib/longleaf/models/filesystem_metadata_location.rb, line 10
def initialize(config)
  super(config)
end

Public Instance Methods

available?() click to toggle source

Checks that the path defined in this metadata location are available @raise [StorageLocationUnavailableError] if the metadata location is not available

# 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) click to toggle source

Get the absolute path for the metadata file for the given file path located in this storage location. @param file_path [String] path of the file relative its storage location @return absolute path to the metadata @raise [ArgumentError] if the file_path is not provided.

# File lib/longleaf/models/filesystem_metadata_location.rb, line 23
def metadata_path_for(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::metadata_suffix
  end
end
relativize(md_path) click to toggle source

Get the metadata path relative to this location @param md_path [String] metadata file path @return the metadata path relative to this location @raise [ArgumentError] if the metadata path is not contained by this location

# 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
type() click to toggle source

@return the storage type for this location

# File lib/longleaf/models/filesystem_metadata_location.rb, line 15
def type
  StorageTypes::FILESYSTEM_STORAGE_TYPE
end