class Listen::Adapter::Windows

Adapter implementation for Windows ‘wdm`.

Constants

BUNDLER_DECLARE_GEM
OS_REGEXP

Public Class Methods

usable?() click to toggle source
Calls superclass method Listen::Adapter::Base::usable?
# File lib/listen/adapter/windows.rb, line 15
def self.usable?
  return false unless super
  require 'wdm'
  true
rescue LoadError
  Listen.logger.debug format('wdm - load failed: %s:%s', $ERROR_INFO,
                             $ERROR_POSITION * "\n")

  Kernel.warn BUNDLER_DECLARE_GEM
  false
end

Private Instance Methods

_change(type) click to toggle source

rubocop:enable Metrics/MethodLength

# File lib/listen/adapter/windows.rb, line 87
def _change(type)
  { modified: [:modified, :attrib], # TODO: is attrib really passed?
    added:    [:added, :renamed_new_file],
    removed:  [:removed, :renamed_old_file] }.find do |change, types|
    types.include?(type) and break change
  end
end
_configure(dir) { |:file, change| ... } click to toggle source
# File lib/listen/adapter/windows.rb, line 29
def _configure(dir)
  require 'wdm'
  Listen.logger.debug 'wdm - starting...'
  @worker ||= WDM::Monitor.new
  @worker.watch_recursively(dir.to_s, :files) do |change|
    yield([:file, change])
  end

  @worker.watch_recursively(dir.to_s, :directories) do |change|
    yield([:dir, change])
  end

  @worker.watch_recursively(dir.to_s, :attributes, :last_write) do |change|
    yield([:attr, change])
  end
end
_process_event(dir, event) click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/listen/adapter/windows.rb, line 51
def _process_event(dir, event)
  Listen.logger.debug "wdm - callback: #{event.inspect}"

  type, change = event

  full_path = Pathname(change.path)

  rel_path = full_path.relative_path_from(dir).to_s

  options = { change: _change(change.type) }

  case type
  when :file
    _queue_change(:file, dir, rel_path, options)
  when :attr
    unless full_path.directory?
      _queue_change(:file, dir, rel_path, options)
    end
  when :dir
    case change.type
    when :removed
      # TODO: check if watched dir?
      _queue_change(:dir, dir, Pathname(rel_path).dirname.to_s, {})
    when :added
      _queue_change(:dir, dir, rel_path, {})
      # do nothing - changed directory means either:
      #   - removed subdirs (handled above)
      #   - added subdirs (handled above)
      #   - removed files (handled by _file_callback)
      #   - added files (handled by _file_callback)
      # so what's left?
    end
  end
end
_run() click to toggle source
# File lib/listen/adapter/windows.rb, line 46
def _run
  @worker.run!
end