Class: DuckTest::Platforms::Linux::Listener

Inherits:
Object
  • Object
show all
Includes:
LoggerHelper, DuckTest::Platforms::Listener
Defined in:
lib/duck_test/platforms/linux/listener.rb

Overview

Listener that wraps the native file system notifier for Linux.

Instance Attribute Summary (collapse)

Attributes included from DuckTest::Platforms::Listener

#block

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from DuckTest::Platforms::Listener

#call_listener_event, #changed?, #changed_files, #dir_list, #file_list, #listener_event, #refresh, #speed, #speed=, #stop, #stop=, #update_all, #update_file_spec, #watch_file_spec, #watched?

Methods included from LoggerHelper

#ducklog

Constructor Details

- (Listener) initialize

A new instance of Listener



15
16
17
18
# File 'lib/duck_test/platforms/linux/listener.rb', line 15

def initialize
  super()
  self.mechanism = INotify::Notifier.new
end

Instance Attribute Details

- (Object) mechanism

Returns the value of attribute mechanism



12
13
14
# File 'lib/duck_test/platforms/linux/listener.rb', line 12

def mechanism
  @mechanism
end

- (Object) thread

Returns the value of attribute thread



11
12
13
# File 'lib/duck_test/platforms/linux/listener.rb', line 11

def thread
  @thread
end

Class Method Details

+ (Boolean) available?

Returns:

  • (Boolean)


21
22
23
# File 'lib/duck_test/platforms/linux/listener.rb', line 21

def self.available?
  return defined?(INotify::Notifier)
end

Instance Method Details

- (Object) start



26
27
28
29
30
31
32
33
34
35
# File 'lib/duck_test/platforms/linux/listener.rb', line 26

def start

  self.thread = Thread.new do
    until self.stop do
      self.mechanism.process
      sleep(self.speed)
    end
  end

end

- (Object) watch(file_spec)



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/duck_test/platforms/linux/listener.rb', line 38

def watch(file_spec)

  self.mechanism.watch file_spec, :close_write, :moved_from, :moved_to, :create, :delete, :delete_self do |event|

    value = :unknown

    event.flags.each do |flag|
      value = flag == :close_write ? :update : value
      value = flag == :create ? :create : value
      value = flag == :delete || flag == :delete_self ? :destroy : value
      value = flag == :moved_from || flag == :moved_from ? :move : value
      break unless value == :unknown
    end

    unless value == :unknown
      self.call_listener_event(WatchEvent.new(self, event.absolute_name, value, event))
    end

  end

end