class Filewatcher::SpecHelper::RubyWatchRun
Ruby API watcher for specs
Attributes
filewatcher[R]
processed[R]
thread[R]
watched[R]
Public Class Methods
new(filewatcher:, **args)
click to toggle source
Calls superclass method
Filewatcher::SpecHelper::WatchRun::new
# File lib/filewatcher/spec_helper/ruby_watch_run.rb, line 13 def initialize(filewatcher:, **args) super(**args) @filewatcher = filewatcher @mutex = Mutex.new end
Public Instance Methods
start()
click to toggle source
Calls superclass method
Filewatcher::SpecHelper::WatchRun#start
# File lib/filewatcher/spec_helper/ruby_watch_run.rb, line 20 def start super @thread = thread_initialize # thread needs a chance to start wait seconds: 1 wait do keep_watching = filewatcher.keep_watching debug "keep_watching = #{keep_watching}" keep_watching end end
stop()
click to toggle source
Calls superclass method
Filewatcher::SpecHelper::WatchRun#stop
# File lib/filewatcher/spec_helper/ruby_watch_run.rb, line 32 def stop thread.exit wait do thread.stop? end super end
wait(seconds: 1)
click to toggle source
Calls superclass method
# File lib/filewatcher/spec_helper/ruby_watch_run.rb, line 42 def wait(seconds: 1) super seconds: seconds, interval: filewatcher.interval end
Private Instance Methods
increment_watched()
click to toggle source
# File lib/filewatcher/spec_helper/ruby_watch_run.rb, line 82 def increment_watched @watched += 1 end
make_changes()
click to toggle source
Calls superclass method
Filewatcher::SpecHelper::WatchRun#make_changes
# File lib/filewatcher/spec_helper/ruby_watch_run.rb, line 48 def make_changes super # Some OS, file systems and Ruby interpretators # doesn't catch milliseconds of `File.mtime` wait do @mutex.synchronize do debug "processed = #{processed}" debug "processed.any? = #{processed.any?}" processed.any? end end end
setup_filewatcher()
click to toggle source
# File lib/filewatcher/spec_helper/ruby_watch_run.rb, line 68 def setup_filewatcher debug 'setup_filewatcher' debug filewatcher.inspect filewatcher.watch do |changes| debug filewatcher.inspect @mutex.synchronize do debug "watch callback: changes = #{changes.inspect}" increment_watched @processed.push(changes) # debug 'pushed to processed' end end end
thread_initialize()
click to toggle source
# File lib/filewatcher/spec_helper/ruby_watch_run.rb, line 62 def thread_initialize @watched ||= 0 @processed = [] Thread.new { setup_filewatcher } end