class Driskell::Listen::Change

TODO: rename to Snapshot

Attributes

config[R]
record[R]

Public Class Methods

new(config, record) click to toggle source
# File lib/driskell-listen/change.rb, line 25
def initialize(config, record)
  @config = config
  @record = record
end

Public Instance Methods

invalidate(type, rel_path, options) click to toggle source

Invalidate some part of the snapshot/record (dir, file, subtree, etc.)

# File lib/driskell-listen/change.rb, line 31
def invalidate(type, rel_path, options)
  watched_dir = Pathname.new(record.root)

  change = options[:change]
  cookie = options[:cookie]

  if !cookie && config.silenced?(rel_path, type)
    Driskell::Listen::Logger.debug {  "(silenced): #{rel_path.inspect}" }
    return
  end

  path = watched_dir + rel_path

  Driskell::Listen::Logger.debug do
    log_details = options[:silence] && 'recording' || change || 'unknown'
    "#{log_details}: #{type}:#{path} (#{options.inspect})"
  end

  if change
    options = cookie ? { cookie: cookie } : {}
    config.queue(type, change, watched_dir, rel_path, options)
  else
    if type == :tree
      # Invalid the entire directory tree
      Directory.scan(self, rel_path, **options, recurse: true)
    elsif type == :dir
      # Invalid directory contents, but do not recurse
      Directory.scan(self, rel_path, **options, recurse: false)
    else
      change = File.change(record, rel_path)
      return if !change || options[:silence]
      config.queue(:file, change, watched_dir, rel_path)
    end
  end
rescue RuntimeError => ex
  msg = format(
    '%s#%s crashed %s:%s',
    self.class,
    __method__,
    exinspect,
    ex.backtrace * "\n")
  Driskell::Listen::Logger.error(msg)
  raise
end