Class: Longleaf::MetadataLocation

Inherits:
Object
  • Object
show all
Defined in:
lib/longleaf/models/metadata_location.rb

Overview

A location in which metadata associated with registered files is stored.

Direct Known Subclasses

FilesystemMetadataLocation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ MetadataLocation

Returns a new instance of MetadataLocation.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/longleaf/models/metadata_location.rb', line 11

def initialize(config)
  raise ArgumentError.new("Config parameter is required") unless config
  @path = config[AF::LOCATION_PATH]
  raise ArgumentError.new("Parameter path is required") unless @path
  @path += '/' unless @path.end_with?('/')

  digests = config[AF::METADATA_DIGESTS]
  if digests.nil?
    @digests = []
  elsif digests.is_a?(String)
    @digests = [digests.downcase]
  else
    @digests = digests.map(&:downcase)
  end
  DigestHelper::validate_algorithms(@digests)
end

Instance Attribute Details

#digestsObject (readonly)

Returns the value of attribute digests.



9
10
11
# File 'lib/longleaf/models/metadata_location.rb', line 9

def digests
  @digests
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/longleaf/models/metadata_location.rb', line 8

def path
  @path
end

Instance Method Details

#contains?(md_path) ⇒ Boolean

Returns true if the metadata path is contained by the path for this location.

Parameters:

  • metadata (String)

    path to check

Returns:

  • (Boolean)

    true if the metadata path is contained by the path for this location



43
44
45
# File 'lib/longleaf/models/metadata_location.rb', line 43

def contains?(md_path)
  md_path.start_with?(@path)
end

#relative_file_path_for(md_path) ⇒ Object

Transforms the given metadata path into a relative storage location path

Parameters:

  • md_path (String)

    path of the metadata file or directory to compute file path for.

Returns:



31
32
33
34
35
36
37
38
39
# File 'lib/longleaf/models/metadata_location.rb', line 31

def relative_file_path_for(md_path)
  rel_md_path = relativize(md_path)

  if rel_md_path.end_with?(MetadataSerializer::)
    rel_md_path[0..-MetadataSerializer::.length - 1]
  else
    rel_md_path
  end
end