Skip to content

Running Programmatically

moredip edited this page Nov 8, 2010 · 6 revisions

Example


require 'watchr'
script = Watchr::Script.new
script.watch('foo') { puts 'bar' } # this call doesn't block
contrl = Watchr::Controller.new(script, Watchr.handler.new)
contrl.run

The Script class’s tests use it that way: https://github.com/mynyml/watchr/blob/master/test/test_script.rb

You can also look at other projects that use watchr as a lib:

How to mix with a glob


all = Dir['lib/*.rb'].join('|')
watch(all) { |md| }

How to traverse recursive subdirectories


watch('.*/abc.rb') do |md|; end

the .* automatically expands to include subdirectories.