Class: Longleaf::StorageLocation
- Inherits:
-
Object
- Object
- Longleaf::StorageLocation
- Defined in:
- lib/longleaf/models/storage_location.rb
Overview
Representation of a configured storage location
Direct Known Subclasses
Instance Attribute Summary collapse
-
#metadata_location ⇒ Object
readonly
Returns the value of attribute metadata_location.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#contains?(file_path) ⇒ Boolean
True if the file path is contained by the path for this location.
-
#get_metadata_path_for(file_path) ⇒ Object
Get the path for the metadata file for the given file path located in this storage location.
-
#initialize(name, config, md_loc) ⇒ StorageLocation
constructor
A new instance of StorageLocation.
Constructor Details
#initialize(name, config, md_loc) ⇒ StorageLocation
Returns a new instance of StorageLocation.
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_location ⇒ Object (readonly)
Returns the value of attribute metadata_location.
10 11 12 |
# File 'lib/longleaf/models/storage_location.rb', line 10 def @metadata_location end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/longleaf/models/storage_location.rb', line 8 def name @name end |
#path ⇒ Object (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.
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.
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 |