class Longleaf::StorageLocation

Representation of a configured storage location

Attributes

metadata_location[R]
name[R]
path[R]

Public Class Methods

new(name, config, md_loc) click to toggle source

@param name [String] the name of this storage location @param config [Hash] hash containing the configuration options for this location @param md_loc [MetadataLocation] metadata location associated with this storage location

# File lib/longleaf/models/storage_location.rb, line 15
def initialize(name, config, md_loc)
  raise ArgumentError.new("Config parameter is required") unless config
  @path = config[AF::LOCATION_PATH]
  @name = name
  raise ArgumentError.new("Parameters name, path and metadata location are required") unless @name && @path && md_loc
  @metadata_location = md_loc
end

Public Instance Methods

contains?(file_path) click to toggle source

@param [String] path to check @return true if the file path is contained by the path for this location

# File lib/longleaf/models/storage_location.rb, line 38
def contains?(file_path)
  file_path.start_with?(@path)
end
get_metadata_path_for(file_path) click to toggle source

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

# File lib/longleaf/models/storage_location.rb, line 26
def get_metadata_path_for(file_path)
  raise ArgumentError.new("A file_path parameter is required") if file_path.nil? || file_path.empty?
  raise ArgumentError.new("Provided file path is not contained by storage location #{@name}: #{file_path}") \
      unless file_path.start_with?(@path)

  rel_file_path = relativize(file_path)

  @metadata_location.metadata_path_for(rel_file_path)
end