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
Constant Summary collapse
- @@storage_type_mappings =
Mapping of storage types to storage location classes
{ ST::FILESYSTEM_STORAGE_TYPE => Longleaf::FilesystemStorageLocation, ST::S3_STORAGE_TYPE => Longleaf::S3StorageLocation }
- @@metadata_type_mappings =
{ ST::FILESYSTEM_STORAGE_TYPE => Longleaf::FilesystemMetadataLocation }
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.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/longleaf/services/storage_location_manager.rb', line 24 def initialize(config) raise ArgumentError.new("Configuration must be provided") if config&.empty? @locations = Hash.new config[AF::LOCATIONS].each do |name, properties| md_loc = (properties) @locations[name] = instantiate_storage_location(name, properties, md_loc) end @locations.freeze end |
Instance Attribute Details
#locations ⇒ Object (readonly)
Hash mapping storage location names to Longleaf::StorageLocation objects
15 16 17 |
# File 'lib/longleaf/services/storage_location_manager.rb', line 15 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
51 52 53 54 55 56 57 58 |
# File 'lib/longleaf/services/storage_location_manager.rb', line 51 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 location..contains?(md_path) end nil end |
#get_location_by_path(path) ⇒ Longleaf::StorageLocation
Get the Longleaf::StorageLocation object which should contain the given path
39 40 41 42 43 44 45 46 |
# File 'lib/longleaf/services/storage_location_manager.rb', line 39 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 location.contains?(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
66 67 68 69 70 71 72 73 74 |
# File 'lib/longleaf/services/storage_location_manager.rb', line 66 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 |