class Photish::Cache::Manifest

Attributes

cache[R]
output_dir[R]
version_hash[R]
worker_db[R]
worker_index[R]
workers[R]

Public Class Methods

new(output_dir, workers, worker_index, version_hash) click to toggle source
# File lib/photish/cache/manifest.rb, line 4
def initialize(output_dir, workers, worker_index, version_hash)
  @output_dir = output_dir
  @workers = workers
  @worker_index = worker_index
  @version_hash = version_hash
  @cache = {}
  @worker_db = {}
end

Public Instance Methods

changed?(key, file_path = nil) click to toggle source
# File lib/photish/cache/manifest.rb, line 19
def changed?(key, file_path = nil)
  checksum = checksum_of_file(file_path || key)
  worker_db[key] = checksum
  checksum != master_db[key]
end
flush_to_disk() click to toggle source
# File lib/photish/cache/manifest.rb, line 25
def flush_to_disk
  worker_db_file(worker_index).write(worker_db)
end
load_from_disk() click to toggle source
# File lib/photish/cache/manifest.rb, line 29
def load_from_disk
  master_db
end
record(key, file_path = nil) click to toggle source
# File lib/photish/cache/manifest.rb, line 13
def record(key, file_path = nil)
  checksum = checksum_of_file(file_path || key)
  worker_db[key] = checksum
  master_db[key] = checksum
end

Private Instance Methods

checksum_of_file(file_path) click to toggle source
# File lib/photish/cache/manifest.rb, line 46
def checksum_of_file(file_path)
  cache.fetch(file_path.hash) do |key|
    cache[key] = hash(file_path)
  end
end
hash(file_path) click to toggle source
# File lib/photish/cache/manifest.rb, line 52
def hash(file_path)
  version_hash.to_s + Digest::MD5.file(file_path).hexdigest
end
master_db() click to toggle source
# File lib/photish/cache/manifest.rb, line 56
def master_db
  @master_db ||= master_db_file.read
end
repository() click to toggle source
# File lib/photish/cache/manifest.rb, line 60
def repository
  @repository ||= Repository.new(output_dir, workers)
end