Class: Longleaf::StorageLocationManager
- Inherits:
-
Object
- Object
- Longleaf::StorageLocationManager
- Defined in:
- lib/longleaf/services/storage_location_manager.rb
Overview
Manager which loads and provides access to StorageLocation objects
Instance Attribute Summary collapse
-
#locations ⇒ Object
readonly
Hash mapping storage location names to StorageLocation objects.
Instance Method Summary collapse
-
#get_location_by_metadata_path(md_path) ⇒ Longleaf::StorageLocation
Get the StorageLocation object which should contain the given metadata path.
-
#get_location_by_path(path) ⇒ Longleaf::StorageLocation
Get the StorageLocation object which should contain the given path.
-
#initialize(config) ⇒ StorageLocationManager
constructor
A new instance of StorageLocationManager.
-
#verify_path_in_location(path, expected_loc = nil) ⇒ StorageLocation
Raises a StorageLocationUnavailableError if the given path is not in a known storage location, or if it is not within the expected location if provided.
Constructor Details
#initialize(config) ⇒ StorageLocationManager
Returns a new instance of StorageLocationManager.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/longleaf/services/storage_location_manager.rb', line 14 def initialize(config) raise ArgumentError.new("Configuration must be provided") if config&.empty? @locations = Hash.new config[AF::LOCATIONS].each do |name, properties| path = properties[AF::LOCATION_PATH] md_path = properties[AF::METADATA_PATH] md_digests = properties[AF::METADATA_DIGESTS] location = Longleaf::StorageLocation.new(name: name, path: path, metadata_path: md_path, metadata_digests: md_digests) @locations[name] = location end @locations.freeze end |
Instance Attribute Details
#locations ⇒ Object (readonly)
Hash mapping storage location names to Longleaf::StorageLocation objects
11 12 13 |
# File 'lib/longleaf/services/storage_location_manager.rb', line 11 def locations @locations end |
Instance Method Details
#get_location_by_metadata_path(md_path) ⇒ Longleaf::StorageLocation
Get the Longleaf::StorageLocation object which should contain the given metadata path
47 48 49 50 51 52 53 54 |
# File 'lib/longleaf/services/storage_location_manager.rb', line 47 def (md_path) raise ArgumentError.new("Metadata path parameter is required") if md_path.nil? || md_path.empty? @locations.each do |name, location| return location if md_path.start_with?(location.) end nil end |
#get_location_by_path(path) ⇒ Longleaf::StorageLocation
Get the Longleaf::StorageLocation object which should contain the given path
35 36 37 38 39 40 41 42 |
# File 'lib/longleaf/services/storage_location_manager.rb', line 35 def get_location_by_path(path) raise ArgumentError.new("Path parameter is required") if path.nil? || path.empty? @locations.each do |name, location| return location if path.start_with?(location.path) end nil end |
#verify_path_in_location(path, expected_loc = nil) ⇒ StorageLocation
Raises a Longleaf::StorageLocationUnavailableError if the given path is not in a known storage location,
or if it is not within the expected location if provided
62 63 64 65 66 67 68 69 70 |
# File 'lib/longleaf/services/storage_location_manager.rb', line 62 def verify_path_in_location(path, expected_loc = nil) location = get_location_by_path(path) if location.nil? raise StorageLocationUnavailableError.new("Path #{path} is not from a known storage location.") elsif !expected_loc.nil? && expected_loc != location.name raise StorageLocationUnavailableError.new("Path #{path} is not contained by storage location #{expected_loc}.") end location end |