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
relink_identicals()
click to toggle source
# File lib/relinker/linker.rb, line 12 def relink_identicals loop_identicals do |checksum, identicals| next if identicals.count <= 1 origin = identicals.shift identicals.each do |identical| # Check if file exists for the case when it was removed # while the script was running system("ln -f #{origin} #{identical}") if File.exist?(origin) end end 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