class Relinker::Linker

Attributes

cache_file[R]
options[R]

Public Class Methods

new(cache_file, options = {}) click to toggle source
# File lib/relinker/linker.rb, line 6
def initialize(cache_file, options = {})
  @cache_file = cache_file
  @options = options
  reset_state
end

Public Instance Methods

loop_files() { |split("$$$\t").map(&:strip)| ... } click to toggle source
# File lib/relinker/linker.rb, line 32
def loop_files
  File.open(@cache_file, "r") do |cache|
    cache.each do |line|
      yield line.split("$$$\t").map(&:strip)
    end
  end
end
loop_identicals(&block) click to toggle source
# File lib/relinker/linker.rb, line 24
def loop_identicals(&block)
  loop_files do |checksum, file|
    publish_state(&block) if checksum != @prev_checksum
    update_state(checksum, file)
  end
  publish_state(&block)
end

Private Instance Methods

publish_state() { |prev_checksum, identicals| ... } click to toggle source
# File lib/relinker/linker.rb, line 42
def publish_state
  yield(@prev_checksum, @identicals) unless @identicals.empty?
  reset_state
end
reset_state() click to toggle source
# File lib/relinker/linker.rb, line 52
def reset_state
  @prev_checksum = nil
  @identicals = []
end
update_state(checksum, file) click to toggle source
# File lib/relinker/linker.rb, line 47
def update_state(checksum, file)
  @prev_checksum = checksum
  @identicals << file
end