Class: Longleaf::RegisteredFileSelector

Inherits:
FileSelector show all
Includes:
Logging
Defined in:
lib/longleaf/candidates/registered_file_selector.rb

Overview

Selects and allows for iteration over files which are registered and match a provided set of selection criteria

Constant Summary

Constants inherited from FileSelector

FileSelector::SPECIFICITY_PATH, FileSelector::SPECIFICITY_STORAGE_LOCATION

Instance Attribute Summary

Attributes inherited from FileSelector

#specificity

Instance Method Summary collapse

Methods included from Logging

#initialize_logger, initialize_logger, #logger, logger

Methods inherited from FileSelector

#each, #initialize, #nil_or_empty?, #storage_locations, #target_paths

Constructor Details

This class inherits a constructor from Longleaf::FileSelector

Instance Method Details

#file_path_for_metadata(md_path) ⇒ Object (private)



60
61
62
63
64
65
# File 'lib/longleaf/candidates/registered_file_selector.rb', line 60

def (md_path)
  storage_loc = @app_config.location_manager.(md_path)
  file_path = storage_loc.(md_path)
  logger.debug("Returning next file #{file_path} for metadata path #{md_path}")
  return file_path
end

#next_pathString

Get the next file path for this selector.

Returns:

  • (String)

    an absolute path to the next file targeted by this selector, or nil if no more files selected

Raises:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/longleaf/candidates/registered_file_selector.rb', line 16

def next_path
  if @md_paths.nil?
    # Compute the starting paths by looking up the metadata paths for the provided targets,
    # in reverse order since @md_paths is a LIFO stack structure.
    @md_paths = target_paths.reverse_each.map do |file_path|
      storage_loc = @app_config.location_manager.verify_path_in_location(file_path)
      storage_loc.(file_path)
    end
  end

  # No more paths to return
  return nil if @md_paths&.empty?

  # Get the most recently added path for depth first traversal of selected paths
  md_path = @md_paths.pop
  until md_path.nil? do
    if File.exist?(md_path)
      if File.directory?(md_path)
        logger.debug("Expanding metadata directory #{md_path}")
        # For a directory, add all children to file_paths
        Dir.entries(md_path).sort.reverse_each do |child|
          @md_paths << File.join(md_path, child) unless child == '.' or child == '..'
        end
      elsif md_path.end_with?(MetadataSerializer::)
        # Convert metadata path to file path before returning
        return (md_path)
      else
        logger.debug("Skipping non-metadata file in metadata directory #{md_path}")
      end
    else
      file_path = (md_path)
      if File.exist?(file_path)
        raise RegistrationError.new("File #{file_path} is not registered.")
      else
        raise InvalidStoragePathError.new("File #{file_path} does not exist.")
      end
    end

    # Returned path was not a suitable file, try the next path
    md_path = @md_paths.pop
  end
end