Class: Longleaf::FilesystemStorageLocation

Inherits:
StorageLocation show all
Defined in:
lib/longleaf/models/filesystem_storage_location.rb

Overview

A storage location in a local filesystem

Instance Attribute Summary

Attributes inherited from StorageLocation

#metadata_location, #name, #path

Instance Method Summary collapse

Methods inherited from StorageLocation

#contains?, #get_metadata_path_for

Constructor Details

#initialize(name, config, md_loc) ⇒ FilesystemStorageLocation

Returns a new instance of FilesystemStorageLocation.

Parameters:

  • name (String)

    the name of this storage location

  • config (Hash)

    hash containing the configuration options for this location

  • md_loc (MetadataLocation)

    metadata location associated with this storage location



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

def initialize(name, config, md_loc)
  super(name, config, md_loc)
  @path += File::SEPARATOR unless @path.end_with?(File::SEPARATOR)
end

Instance Method Details

#available?Boolean

Checks that the path and metadata path defined in this location are available

Returns:

  • (Boolean)

Raises:



34
35
36
37
38
# File 'lib/longleaf/models/filesystem_storage_location.rb', line 34

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

#get_path_from_metadata_path(md_path) ⇒ String

Get that absolute path to the file associated with the provided metadata path

Parameters:

  • md_path (String)

    metadata file path

Returns:

  • (String)

    the path for the file associated with this metadata

Raises:

  • (ArgumentError)

    if the md_path is not in this storage location



24
25
26
27
28
29
30
# File 'lib/longleaf/models/filesystem_storage_location.rb', line 24

def (md_path)
  raise ArgumentError.new("A file_path parameter is required") if md_path.nil? || md_path.empty?

  rel_path = @metadata_location.relative_file_path_for(md_path)

  File.join(@path, rel_path)
end

#relativize(file_path) ⇒ Object

Get the file path relative to this location

Parameters:

  • file_path (String)

    file path

Returns:

  • the file path relative to this location

Raises:

  • (ArgumentError)

    if the file path is not contained by this location



44
45
46
47
48
49
50
# File 'lib/longleaf/models/filesystem_storage_location.rb', line 44

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

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

  file_path.sub(@path, "")
end

#typeObject

Returns the storage type for this location.

Returns:

  • the storage type for this location



16
17
18
# File 'lib/longleaf/models/filesystem_storage_location.rb', line 16

def type
  StorageTypes::FILESYSTEM_STORAGE_TYPE
end