class Spring::Watcher::Abstract
watcher.stale? # => true<br>IO.select() # watcher is running in background
watcher = MyWatcher.new(root, latency)
A user of a watcher can use IO.select to wait for changes:
def add(*items)
def add(*items) items = items.flatten.map do |item| item = Pathname.new(item) if item.relative? Pathname.new("#{root}/#{item}") else item end end items = items.select(&:exist?) synchronize { items.each do |item| if item.directory? directories << item.realpath.to_s else files << item.realpath.to_s end end subjects_changed } end
def initialize(root, latency)
def initialize(root, latency) super() @root = File.realpath(root) @latency = latency @files = Set.new @directories = Set.new @stale = false @listeners = [] end
def mark_stale
def mark_stale return if stale? @stale = true @listeners.each(&:call) end
def on_stale(&block)
def on_stale(&block) @listeners << block end
def restart
def restart stop start end
def stale?
def stale? @stale end
def start
def start raise NotImplementedError end
def stop
def stop raise NotImplementedError end
def subjects_changed
def subjects_changed raise NotImplementedError end