# class Listen::Change

### Attributes

listener[RW]

### Public Class Methods

new(listener) click to toggle source

    # File lib/listen/change.rb, line 10
    def initialize(listener)
      @listener = listener
    end

### Public Instance Methods

change(type, watched_dir, rel_path, options = {}) click to toggle source

    # File lib/listen/change.rb, line 14
    def change(type, watched_dir, rel_path, options = {})
      change = options[:change]
      cookie = options[:cookie]

      if !cookie && listener.silencer.silenced?(Pathname(rel_path), type)
        _log :debug, "(silenced): #{rel_path.inspect}"
        return
      end

      path = watched_dir + rel_path

      log_details = options[:silence] && 'recording' || change || 'unknown'
      _log :debug, "#{log_details}: #{type}:#{path} (#{options.inspect})"

      if change
        # TODO: move this to Listener to avoid Celluloid overhead
        # from caller
        options = cookie ? { cookie: cookie } : {}
        listener.queue(type, change, watched_dir, rel_path, options)
      else
        return unless (record = listener.sync(:record))

        if type == :dir
          return unless (change_queue = listener.async(:change_pool))
          Directory.scan(change_queue, record, watched_dir, rel_path, options)
        else
          change = File.change(record, watched_dir, rel_path)
          return if !change || options[:silence]
          listener.queue(:file, change, watched_dir, rel_path)
        end
      end
    rescue Celluloid::Task::TerminatedError
      _log :debug, "Change#change was terminated: #{$ERROR_INFO.inspect}"
    rescue RuntimeError
      _log :error, format('Change#change crashed %s:%s', $ERROR_INFO.inspect,
                          $ERROR_POSITION * "\n")
      raise
    end

### Private Instance Methods

_log(type, message) click to toggle source

    # File lib/listen/change.rb, line 55
    def _log(type, message)
      Celluloid::Logger.send(type, message)
    end