Class: Listen::Compat::Wrapper::Ancient

Inherits:
Common
  • Object
show all
Defined in:
lib/listen/compat/wrapper.rb

Overview

Workarounds for pre 2.0 versions of Listen

Constant Summary collapse

NEXT_VERSION =
Gem::Version.new('2.0.0')

Instance Method Summary collapse

Instance Method Details

#listen(*args, &block) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/listen/compat/wrapper.rb', line 115

def listen(*args, &block)
  options     = args.last.is_a?(Hash) ? args.pop : {}
  # Note: force_polling is a method here (since Listen 2.0.0 it's an
  # option passed to Listen.new)
  poll = options[:force_polling]

  directories = watchable_directories(args.flatten)

  # Don't optimize this out because of Ruby 1.8
  args = directories
  args << options

  listener = _listen_class.new(*args, &block)
  listener.force_polling(true) if poll
  listener.start!
rescue Interrupt
end

#watchable_directories(directories) ⇒ Object

A Listen version prior to 2.0 will write a test file to a directory to see if a watcher supports watching that directory. That breaks horribly on read-only directories, so we filter those out.



111
112
113
# File 'lib/listen/compat/wrapper.rb', line 111

def watchable_directories(directories)
  directories.select { |d| ::File.directory?(d) && ::File.writable?(d) }
end