class Spring::Watcher::Polling

Attributes

mtime[R]

Public Class Methods

new(root, latency) click to toggle source
Calls superclass method Spring::Watcher::Abstract.new
# File lib/spring/watcher/polling.rb, line 8
def initialize(root, latency)
  super
  @mtime  = 0
  @poller = nil
end

Public Instance Methods

add(*) click to toggle source
Calls superclass method Spring::Watcher::Abstract#add
# File lib/spring/watcher/polling.rb, line 18
def add(*)
  check_stale if @poller
  super
end
check_stale() click to toggle source
# File lib/spring/watcher/polling.rb, line 14
def check_stale
  synchronize { mark_stale if mtime < compute_mtime }
end
start() click to toggle source
# File lib/spring/watcher/polling.rb, line 23
def start
  unless @poller
    @poller = Thread.new {
      Thread.current.abort_on_exception = true

      loop do
        Kernel.sleep latency
        check_stale
      end
    }
  end
end
stop() click to toggle source
# File lib/spring/watcher/polling.rb, line 36
def stop
  if @poller
    @poller.kill
    @poller = nil
  end
end
subjects_changed() click to toggle source
# File lib/spring/watcher/polling.rb, line 43
def subjects_changed
  @mtime = compute_mtime
end

Private Instance Methods

compute_mtime() click to toggle source
# File lib/spring/watcher/polling.rb, line 49
def compute_mtime
  expanded_files.map { |f| File.mtime(f).to_f }.max || 0
rescue Errno::ENOENT
  # if a file does no longer exist, the watcher is always stale.
  Float::MAX
end
expanded_files() click to toggle source
# File lib/spring/watcher/polling.rb, line 56
def expanded_files
  files + Dir["{#{directories.map { |d| "#{d}/**/*" }.join(",")}}"]
end