Class: Coyote::FSListeners::Linux

Inherits:
Base
  • Object
show all
Defined in:
lib/coyote/fs_listeners/linux.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#last_event, #sha1_checksums_hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#modified_files, #update_last_event

Constructor Details

#initializeLinux

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

#callbackObject (readonly)

Returns the value of attribute callback.



3
4
5
# File 'lib/coyote/fs_listeners/linux.rb', line 3

def callback
  @callback
end

#filesObject (readonly)

Returns the value of attribute files.



3
4
5
# File 'lib/coyote/fs_listeners/linux.rb', line 3

def files
  @files
end

#inotifyObject (readonly)

Returns the value of attribute inotify.



3
4
5
# File 'lib/coyote/fs_listeners/linux.rb', line 3

def inotify
  @inotify
end

#latencyObject (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

Returns:

  • (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

#startObject



13
14
15
16
# File 'lib/coyote/fs_listeners/linux.rb', line 13

def start
  @stop = false
  watch_change unless watch_change?
end

#stopObject



18
19
20
21
# File 'lib/coyote/fs_listeners/linux.rb', line 18

def stop
  @stop = true
  sleep latency
end

#watch_change?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/coyote/fs_listeners/linux.rb', line 46

def watch_change?
  !!@watch_change
end