Class: Longleaf::FilesystemMetadataLocation
- Inherits:
-
MetadataLocation
- Object
- MetadataLocation
- Longleaf::FilesystemMetadataLocation
- Defined in:
- lib/longleaf/models/filesystem_metadata_location.rb
Overview
A filesystem based location in which metadata associated with registered files is stored.
Instance Attribute Summary
Attributes inherited from MetadataLocation
Instance Method Summary collapse
-
#available? ⇒ Boolean
Checks that the path defined in this metadata location are available.
-
#initialize(config) ⇒ FilesystemMetadataLocation
constructor
A new instance of FilesystemMetadataLocation.
-
#metadata_path_for(file_path) ⇒ Object
Get the absolute path for the metadata file for the given file path located in this storage location.
-
#relativize(md_path) ⇒ Object
Get the metadata path relative to this location.
-
#type ⇒ Object
The storage type for this location.
Methods inherited from MetadataLocation
#contains?, #relative_file_path_for
Constructor Details
#initialize(config) ⇒ FilesystemMetadataLocation
Returns a new instance of FilesystemMetadataLocation.
10 11 12 |
# File 'lib/longleaf/models/filesystem_metadata_location.rb', line 10 def initialize(config) super(config) end |
Instance Method Details
#available? ⇒ Boolean
Checks that the path defined in this metadata location are available
51 52 53 54 |
# File 'lib/longleaf/models/filesystem_metadata_location.rb', line 51 def available? raise StorageLocationUnavailableError.new("Metadata path does not exist or is not a directory: #{@path}")\ unless Dir.exist?(@path) end |
#metadata_path_for(file_path) ⇒ Object
Get the absolute path for the metadata file for the given file path located in this storage location.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/longleaf/models/filesystem_metadata_location.rb', line 23 def (file_path) raise ArgumentError.new("A file_path parameter is required") if file_path.nil? raise ArgumentError.new("File path must be relative") if Pathname.new(file_path).absolute? md_path = File.join(@path, file_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 |
#relativize(md_path) ⇒ Object
Get the metadata path relative to this location
40 41 42 43 44 45 46 |
# File 'lib/longleaf/models/filesystem_metadata_location.rb', line 40 def relativize(md_path) return md_path if Pathname.new(md_path).relative? raise ArgumentError.new("Metadata path must be contained by this location") if !md_path.start_with?(@path) md_path.sub(@path, "") end |
#type ⇒ Object
Returns the storage type for this location.
15 16 17 |
# File 'lib/longleaf/models/filesystem_metadata_location.rb', line 15 def type StorageTypes::FILESYSTEM_STORAGE_TYPE end |