Class: FeatherWatch::Watcher
- Inherits:
-
Object
- Object
- FeatherWatch::Watcher
- Defined in:
- lib/feather_watch/watcher.rb
Instance Method Summary collapse
-
#initialize(directories, callback, verbose = false, silence_exceptions = false) ⇒ Watcher
constructor
Public: Initialize the file system watcher.
-
#start ⇒ Object
Public: Starts the watcher.
-
#stop ⇒ Object
Public: Stops the watcher.
Constructor Details
#initialize(directories, callback, verbose = false, silence_exceptions = false) ⇒ Watcher
Public: Initialize the file system watcher.
directories - An array of directories to watch. callback - A callback that will receive events. Recieved objects on form: [:modified, :removed].sample, file: “path/to/file”. “:modified” means everything except deleted. verbose=false - Enable verbose mode. Warning: Can produce very much output
Examples
FeatherWatch::Watcher.new([File.join(Dir.home, 'Desktop')], lambda{|e| puts "got event with status: #{e[:status]} on file #{e[:file]}"})
Returns a Watcher object.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/feather_watch/watcher.rb', line 15 def initialize(directories, callback, verbose= false, silence_exceptions= false) @verbose = verbose dir = directories dir = [directories] if directories.is_a?(String) raise "Unknown datatype for directories. Was: #{dir}" unless dir.is_a?(Array) dir.each do |d| raise "Not a vaild directory: #{d}" unless File.directory?(d) end @listener = FeatherWatch::Core::DarwinWatcher.new(dir, callback, verbose, silence_exceptions) if FeatherWatch::OS.mac? @listener = FeatherWatch::Core::LinuxWatcher.new(dir, callback, verbose, silence_exceptions) if FeatherWatch::OS.linux? @listener = FeatherWatch::Core::WindowsWatcher.new(dir, callback, verbose, silence_exceptions) if FeatherWatch::OS.windows? end |
Instance Method Details
#start ⇒ Object
Public: Starts the watcher.
Examples
watcher.start
# => nil
Returns nil
38 39 40 |
# File 'lib/feather_watch/watcher.rb', line 38 def start @listener.start if @listener end |
#stop ⇒ Object
Public: Stops the watcher.
Examples
watcher.start
# => nil
Returns nil
50 51 52 |
# File 'lib/feather_watch/watcher.rb', line 50 def stop @listener.stop if @listener end |