Class: Longleaf::StorageLocation

Inherits:
Object
  • Object
show all
Defined in:
lib/longleaf/models/storage_location.rb

Overview

Representation of a configured storage location

Direct Known Subclasses

FilesystemStorageLocation, S3StorageLocation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, config, md_loc) ⇒ StorageLocation

Returns a new instance of StorageLocation.

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

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
# 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

Instance Attribute Details

#metadata_locationObject (readonly)

Returns the value of attribute metadata_location.



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

def 
  @metadata_location
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/longleaf/models/storage_location.rb', line 8

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/longleaf/models/storage_location.rb', line 9

def path
  @path
end

Instance Method Details

#contains?(file_path) ⇒ Boolean

Returns true if the file path is contained by the path for this location.

Parameters:

  • path (String)

    to check

Returns:

  • (Boolean)

    true if the file path is contained by the path for this location



38
39
40
# 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) ⇒ Object

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

Parameters:

  • file_path (String)

    path of the file

Raises:

  • (ArgumentError)

    if the file_path is not provided or is not in this storage location.



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

def (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.(rel_file_path)
end