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 24 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 do computed = compute_mtime if mtime < computed debug { "check_stale: mtime=#{mtime.inspect} < computed=#{computed.inspect}" } mark_stale end end end
running?()
click to toggle source
# File lib/spring/watcher/polling.rb, line 60 def running? @poller && @poller.alive? end
start()
click to toggle source
# File lib/spring/watcher/polling.rb, line 29 def start debug { "start: poller=#{@poller.inspect}" } unless @poller @poller = Thread.new { Thread.current.abort_on_exception = true begin until stale? Kernel.sleep latency check_stale end rescue Exception => e debug do "poller: aborted: #{e.class}: #{e}\n #{e.backtrace.join("\n ")}" end raise ensure @poller = nil end } end end
stop()
click to toggle source
# File lib/spring/watcher/polling.rb, line 52 def stop debug { "stopping poller: #{@poller.inspect}" } if @poller @poller.kill @poller = nil end end
subjects_changed()
click to toggle source
# File lib/spring/watcher/polling.rb, line 64 def subjects_changed computed = compute_mtime debug { "subjects_changed: mtime #{@mtime} -> #{computed}" } @mtime = computed end
Private Instance Methods
compute_mtime()
click to toggle source
# File lib/spring/watcher/polling.rb, line 72 def compute_mtime expanded_files.map do |f| # Get the mtime of symlink targets. Ignore dangling symlinks. if File.symlink?(f) begin File.mtime(f) rescue Errno::ENOENT 0 end # If a file no longer exists, treat it as changed. else begin File.mtime(f) rescue Errno::ENOENT debug { "compute_mtime: no longer exists: #{f}" } Float::MAX end end.to_f end.max || 0 end
expanded_files()
click to toggle source
# File lib/spring/watcher/polling.rb, line 93 def expanded_files files + Dir["{#{directories.map { |d| "#{d}/**/*" }.join(",")}}"] end