class Minipack::FileChangeWatcher

Public Class Methods

new(watched_paths, digest_store_path) click to toggle source

@param [Array<Pathname>] watched_paths @param [Pathname] digest_store_path

# File lib/minipack/file_change_watcher.rb, line 10
def initialize(watched_paths, digest_store_path)
  @watched_paths = watched_paths
  @digest_store_path = Pathname.new(digest_store_path)
end

Public Instance Methods

fresh?() click to toggle source

Returns true if all watched files are up to date

# File lib/minipack/file_change_watcher.rb, line 16
def fresh?
  watched_files_digest == last_stored_digest
end
record_digest() click to toggle source
# File lib/minipack/file_change_watcher.rb, line 25
def record_digest
  @digest_store_path.dirname.mkpath
  @digest_store_path.write(watched_files_digest)
end
stale?() click to toggle source

Returns true if the watched files are out of date

# File lib/minipack/file_change_watcher.rb, line 21
def stale?
  !fresh?
end

Private Instance Methods

last_stored_digest() click to toggle source
# File lib/minipack/file_change_watcher.rb, line 32
def last_stored_digest
  @digest_store_path.read if @digest_store_path.exist?
rescue Errno::ENOENT, Errno::ENOTDIR
end
watched_files_digest() click to toggle source
# File lib/minipack/file_change_watcher.rb, line 37
def watched_files_digest
  files = Dir[*@watched_paths].reject { |f| File.directory?(f) }
  file_ids = files.sort.map { |f| "#{File.basename(f)}/#{Digest::SHA1.file(f).hexdigest}" }
  Digest::SHA1.hexdigest(file_ids.join("/"))
end