Class: Dirwatch::Watcher
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
- #files ⇒ Object
-
#initialize(options) ⇒ Watcher
constructor
A new instance of Watcher.
- #start ⇒ Object
- #stop ⇒ Object
- #wait_for_stop ⇒ Object
Constructor Details
#initialize(options) ⇒ Watcher
Returns a new instance of Watcher.
8 9 10 11 12 13 14 15 |
# File 'lib/dirwatch/watcher.rb', line 8 def initialize = @settings = Settings. return unless .daemonize Process.daemon true, true puts "running in the background... [#{Process.pid}]" end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/dirwatch/watcher.rb', line 5 def end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
6 7 8 |
# File 'lib/dirwatch/watcher.rb', line 6 def settings @settings end |
Instance Method Details
#files ⇒ Object
41 42 43 |
# File 'lib/dirwatch/watcher.rb', line 41 def files Dir[File.join .directory, '**', .file_match] end |
#start ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dirwatch/watcher.rb', line 17 def start raise 'already started' if @threads @threads = [] @stop = false Thread.abort_on_exception = true @settings.by_interval do |interval, watch_settings| watch_settings.each {|ws| puts "Watching #{ws}" } @threads << Thread.new do run interval, watch_settings end end end |
#stop ⇒ Object
35 36 37 38 39 |
# File 'lib/dirwatch/watcher.rb', line 35 def stop raise 'not started' unless @threads @stop = true wait_for_stop end |
#wait_for_stop ⇒ Object
31 32 33 |
# File 'lib/dirwatch/watcher.rb', line 31 def wait_for_stop @threads.each(&:join) end |