Class: Longleaf::StorageLocation
- Inherits:
-
Object
- Object
- Longleaf::StorageLocation
- Defined in:
- lib/longleaf/models/storage_location.rb
Overview
Representation of a configured storage location
Instance Attribute Summary collapse
-
#metadata_digests ⇒ Object
readonly
Returns the value of attribute metadata_digests.
-
#metadata_path ⇒ Object
readonly
Returns the value of attribute metadata_path.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#available? ⇒ Boolean
Checks that the path and metadata path defined in this location are available.
-
#get_metadata_path_for(file_path) ⇒ Object
Get the path for the metadata file for the given file path located in this storage location.
-
#get_path_from_metadata_path(md_path) ⇒ String
Get the metadata path for the provided file path located in this storage location.
-
#initialize(name:, path:, metadata_path:, metadata_digests: []) ⇒ StorageLocation
constructor
A new instance of StorageLocation.
Constructor Details
#initialize(name:, path:, metadata_path:, metadata_digests: []) ⇒ StorageLocation
Returns a new instance of StorageLocation.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/longleaf/models/storage_location.rb', line 15 def initialize(name:, path:, metadata_path:, metadata_digests: []) raise ArgumentError.new("Parameters name, path and metadata_path are required") unless name && path && @path = path @path += '/' unless @path.end_with?('/') @name = name @metadata_path = @metadata_path += '/' unless @metadata_path.end_with?('/') if .nil? @metadata_digests = [] elsif .is_a?(String) @metadata_digests = [.downcase] else @metadata_digests = .map(&:downcase) end DigestHelper::validate_algorithms(@metadata_digests) end |
Instance Attribute Details
#metadata_digests ⇒ Object (readonly)
Returns the value of attribute metadata_digests.
9 10 11 |
# File 'lib/longleaf/models/storage_location.rb', line 9 def @metadata_digests end |
#metadata_path ⇒ Object (readonly)
Returns the value of attribute metadata_path.
8 9 10 |
# File 'lib/longleaf/models/storage_location.rb', line 8 def @metadata_path end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/longleaf/models/storage_location.rb', line 6 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/longleaf/models/storage_location.rb', line 7 def path @path end |
Instance Method Details
#available? ⇒ Boolean
Checks that the path and metadata path defined in this location are available
66 67 68 69 70 71 |
# File 'lib/longleaf/models/storage_location.rb', line 66 def available? raise StorageLocationUnavailableError.new("Path does not exist or is not a directory: #{@path}")\ unless Dir.exist?(@path) raise StorageLocationUnavailableError.new("Metadata path does not exist or is not a directory: #{@metadata_path}")\ unless Dir.exist?(@metadata_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.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/longleaf/models/storage_location.rb', line 37 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) md_path = file_path.sub(/^#{@path}/, @metadata_path) # If the file_path is to a file, then add metadata suffix. if md_path.end_with?('/') md_path else md_path + MetadataSerializer:: end end |
#get_path_from_metadata_path(md_path) ⇒ String
Get the metadata path for the provided file path located in this storage location.
55 56 57 58 59 60 61 62 |
# File 'lib/longleaf/models/storage_location.rb', line 55 def (md_path) raise ArgumentError.new("A file_path parameter is required") if md_path.nil? || md_path.empty? raise ArgumentError.new("Provided metadata path is not contained by storage location #{@name}: #{md_path}") \ unless md_path&.start_with?(@metadata_path) file_path = md_path.sub(/^#{@metadata_path}/, @path) file_path.sub(/#{MetadataSerializer::}$/, '') end |