Class: Longleaf::FilesystemStorageLocation
- Inherits:
-
StorageLocation
- Object
- StorageLocation
- Longleaf::FilesystemStorageLocation
- 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
-
#available? ⇒ Boolean
Checks that the path and metadata path defined in this location are available.
-
#get_path_from_metadata_path(md_path) ⇒ String
Get that absolute path to the file associated with the provided metadata path.
-
#initialize(name, config, md_loc) ⇒ FilesystemStorageLocation
constructor
A new instance of FilesystemStorageLocation.
-
#relativize(file_path) ⇒ Object
Get the file path relative to this location.
-
#type ⇒ Object
The storage type for this location.
Methods inherited from StorageLocation
#contains?, #get_metadata_path_for
Constructor Details
#initialize(name, config, md_loc) ⇒ FilesystemStorageLocation
Returns a new instance of FilesystemStorageLocation.
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
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
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
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 |
#type ⇒ Object
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 |