Class: Coyote::FSListeners::Linux
- Defined in:
- lib/coyote/fs_listeners/linux.rb
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#inotify ⇒ Object
readonly
Returns the value of attribute inotify.
-
#latency ⇒ Object
readonly
Returns the value of attribute latency.
Attributes inherited from Base
#last_event, #sha1_checksums_hash
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Linux
constructor
A new instance of Linux.
- #on_change(&callback) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #watch_change? ⇒ Boolean
Methods inherited from Base
#modified_files, #update_last_event
Constructor Details
#initialize ⇒ Linux
Returns a new instance of Linux.
5 6 7 8 9 10 11 |
# File 'lib/coyote/fs_listeners/linux.rb', line 5 def initialize super @inotify = INotify::Notifier.new @files = [] @latency = 0.5 end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
3 4 5 |
# File 'lib/coyote/fs_listeners/linux.rb', line 3 def callback @callback end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
3 4 5 |
# File 'lib/coyote/fs_listeners/linux.rb', line 3 def files @files end |
#inotify ⇒ Object (readonly)
Returns the value of attribute inotify.
3 4 5 |
# File 'lib/coyote/fs_listeners/linux.rb', line 3 def inotify @inotify end |
#latency ⇒ Object (readonly)
Returns the value of attribute latency.
3 4 5 |
# File 'lib/coyote/fs_listeners/linux.rb', line 3 def latency @latency end |
Class Method Details
.usable? ⇒ Boolean
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/coyote/fs_listeners/linux.rb', line 33 def self.usable? require 'rb-inotify' if !defined?(INotify::VERSION) || Gem::Version.new(INotify::VERSION.join('.')) < Gem::Version.new('0.5.1') notify "Please update rb-inotify (>= 0.5.1)", :failure false else true end rescue LoadError notify "Please install rb-inotify gem for Linux inotify support", :failure false end |
Instance Method Details
#on_change(&callback) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/coyote/fs_listeners/linux.rb', line 23 def on_change(&callback) @callback = callback inotify.watch(Dir.pwd, :recursive, :modify, :create, :delete, :move) do |event| unless event.name == "" # Event on root directory @files << event.absolute_name end end rescue Interrupt end |
#start ⇒ Object
13 14 15 16 |
# File 'lib/coyote/fs_listeners/linux.rb', line 13 def start @stop = false watch_change unless watch_change? end |
#stop ⇒ Object
18 19 20 21 |
# File 'lib/coyote/fs_listeners/linux.rb', line 18 def stop @stop = true sleep latency end |
#watch_change? ⇒ Boolean
46 47 48 |
# File 'lib/coyote/fs_listeners/linux.rb', line 46 def watch_change? !!@watch_change end |