Class: Longleaf::ServiceCandidateFilesystemIterator

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/longleaf/candidates/service_candidate_filesystem_iterator.rb

Overview

Iterator for getting file candidates which have services which need to be run. Implementation uses metadata files directly from the filesystem for determinations about service status.

Instance Method Summary collapse

Methods included from Logging

#initialize_logger, initialize_logger, logger, #logger

Constructor Details

#initialize(file_selector, event, app_config, force = false) ⇒ ServiceCandidateFilesystemIterator

Returns a new instance of ServiceCandidateFilesystemIterator.



14
15
16
17
18
19
# File 'lib/longleaf/candidates/service_candidate_filesystem_iterator.rb', line 14

def initialize(file_selector, event, app_config, force = false)
  @file_selector = file_selector
  @event = event
  @app_config = app_config
  @force = force
end

Instance Method Details

#eachObject

Iterate through the candidates in this object and execute the provided block with each candidate. A block is required.



49
50
51
52
53
54
55
56
# File 'lib/longleaf/candidates/service_candidate_filesystem_iterator.rb', line 49

def each
  file_rec = next_candidate
  until file_rec.nil?
    yield file_rec

    file_rec = next_candidate
  end
end

#next_candidateFileRecord

Get the file record for the next candidate which needs services run which match the provided file_selector or nil if there are no more candidates.

Returns:

  • (FileRecord)

    file record of the next candidate with services needing to be run,



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/longleaf/candidates/service_candidate_filesystem_iterator.rb', line 25

def next_candidate
  loop do
    next_path = @file_selector.next_path
    return nil if next_path.nil?

    logger.debug("Evaluating candidate #{next_path}")
    storage_loc = @app_config.location_manager.get_location_by_path(next_path)
    file_rec = FileRecord.new(next_path, storage_loc)

    # Skip over unregistered files
    if !file_rec.
      logger.debug("Ignoring unregistered file #{next_path}")
      next
    end

    @app_config.md_manager.load(file_rec)

    # Return the file record if it needs any services run
    return file_rec if needs_run?(file_rec)
  end
end