# class Listen::Adapter::Base

### Constants

DEFAULTS

  TODO: only used by tests

### Attributes

options[R]

### Public Class Methods

local_fs?() click to toggle source

    # File lib/listen/adapter/base.rb, line 66
    def self.local_fs?
      true
    end

new(opts) click to toggle source

    # File lib/listen/adapter/base.rb, line 13
    def initialize(opts)
      @configured = nil
      options = opts.dup
      @mq = options.delete(:mq)
      @directories = options.delete(:directories)

      Array(@directories).each do |dir|
        next if dir.is_a?(Pathname)
        fail ArgumentError, "not a Pathname: #{dir.inspect}"
      end

      # TODO: actually use this in every adapter
      @recursion = options.delete(:recursion)
      @recursion = true if @recursion.nil?

      defaults = self.class.const_get('DEFAULTS')
      @options = Listen::Options.new(options, defaults)
    rescue
      _log_exception 'adapter config failed: %s:%s'
      raise
    end

usable?() click to toggle source

    # File lib/listen/adapter/base.rb, line 70
    def self.usable?
      const_get('OS_REGEXP') =~ RbConfig::CONFIG['target_os']
    end

### Private Class Methods

_log(*args, &block) click to toggle source

    # File lib/listen/adapter/base.rb, line 90
    def self._log(*args, &block)
      if block
        Celluloid::Logger.send(*args, block.call)
      else
        Celluloid::Logger.send(*args)
      end
    end

### Public Instance Methods

configure() click to toggle source

TODO: it's a separate method as a temporary workaround for tests

    # File lib/listen/adapter/base.rb, line 36
    def configure
      return if @configured
      @configured = true

      @callbacks ||= {}
      @directories.each do |dir|
        unless dir.is_a?(Pathname)
          fail ArgumentError, "not a Pathname: #{dir.inspect}"
        end

        callback = @callbacks[dir] || lambda do |event|
          _process_event(dir, event)
        end
        @callbacks[dir] = callback
        _configure(dir, &callback)
      end
    end

start() click to toggle source

    # File lib/listen/adapter/base.rb, line 54
    def start
      configure
      Listen::Internals::ThreadPool.add do
        begin
          _run
        rescue
          _log_exception 'run() in thread failed: %s:%s'
          raise
        end
      end
    end

### Private Instance Methods

_log(*args, &block) click to toggle source

    # File lib/listen/adapter/base.rb, line 82
    def _log(*args, &block)
      self.class.send(:_log, *args, &block)
    end

_log_exception(msg) click to toggle source

    # File lib/listen/adapter/base.rb, line 86
    def _log_exception(msg)
      _log :error, format(msg, $ERROR_INFO, $ERROR_POSITION * "\n")
    end

_queue_change(type, dir, rel_path, options) click to toggle source

    # File lib/listen/adapter/base.rb, line 76
    def _queue_change(type, dir, rel_path, options)
      # TODO: temporary workaround to remove dependency on Change through
      # Celluloid in tests
      @mq.send(:_queue_raw_change, type, dir, rel_path, options)
    end