Class: DuckTest::Platforms::Windows::Listener
- Inherits:
-
Object
- Object
- DuckTest::Platforms::Windows::Listener
show all
- Includes:
- LoggerHelper, Listener
- Defined in:
- lib/duck_test/platforms/windows/listener.rb
Overview
Listener that wraps the native file system notifier for Windows.
Instance Attribute Summary (collapse)
Attributes included from Listener
#block
Class Method Summary
(collapse)
Instance Method Summary
(collapse)
Methods included from Listener
#call_listener_event, #changed_files, #dir_list, #listener_event, #refresh, #speed, #speed=, #stop, #stop=, #update_all, #update_file_spec
#ducklog
Constructor Details
A new instance of Listener
18
19
20
21
22
|
# File 'lib/duck_test/platforms/windows/listener.rb', line 18
def initialize
super()
self.mechanism = FChange::Notifier.new
ducklog.console "Platform listener: Windows"
end
|
Instance Attribute Details
- (Object) mechanism
Returns the value of attribute mechanism
15
16
17
|
# File 'lib/duck_test/platforms/windows/listener.rb', line 15
def mechanism
@mechanism
end
|
- (Object) thread
Returns the value of attribute thread
14
15
16
|
# File 'lib/duck_test/platforms/windows/listener.rb', line 14
def thread
@thread
end
|
Class Method Details
+ (Boolean) available?
25
26
27
|
# File 'lib/duck_test/platforms/windows/listener.rb', line 25
def self.available?
return defined?(FChange::Notifier)
end
|
Instance Method Details
- (Boolean) changed?(file_spec)
41
42
43
44
45
46
47
48
|
# File 'lib/duck_test/platforms/windows/listener.rb', line 41
def changed?(file_spec)
value = false
file_object = self.file_list[file_spec]
if file_object && !file_object[:is_dir]
value = File.mtime(file_spec).to_f > file_object[:mtime] || !Digest::SHA1.file(file_spec).to_s.eql?(file_object[:sha])
end
return value
end
|
- (Object) file_list
30
31
32
33
|
# File 'lib/duck_test/platforms/windows/listener.rb', line 30
def file_list
@file_list ||= {}
return @file_list
end
|
- (Object) start
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/duck_test/platforms/windows/listener.rb', line 60
def start
self.file_list.each do |file_object|
if file_object.last[:is_dir]
@mechanism.watch file_object.first, :all_events, :recursive do |dir|
dir_spec = dir.watcher.path
if self.watched?(dir_spec)
changed_files = []
list = Dir.glob "#{dir_spec}/*"
list.each do |item|
if self.watched?(item)
if self.changed?(item)
self.watch_file_spec(item)
changed_files.push(item)
end
else
self.watch_file_spec(item)
changed_files.push(item)
end
end
changed_files.each do |item|
self.call_listener_event(WatchEvent.new(self, item, :update, nil))
end
end
end
end
end
self.thread = Thread.new do
until self.stop do
@mechanism.run
sleep(self.speed)
end
end
end
|
- (Object) watch(file_spec)
103
104
105
|
# File 'lib/duck_test/platforms/windows/listener.rb', line 103
def watch(file_spec)
watch_file_spec(file_spec)
end
|
- (Object) watch_file_spec(file_spec)
51
52
53
54
55
56
57
|
# File 'lib/duck_test/platforms/windows/listener.rb', line 51
def watch_file_spec(file_spec)
buffer = {}
buffer[:is_dir] = File.directory?(file_spec)
buffer[:mtime] = File.mtime(file_spec).to_f
buffer[:sha] = Digest::SHA1.file(file_spec).to_s unless buffer[:is_dir]
self.file_list[file_spec] = buffer
end
|
- (Boolean) watched?(file_spec)
36
37
38
|
# File 'lib/duck_test/platforms/windows/listener.rb', line 36
def watched?(file_spec)
return self.file_list[file_spec] ? true : false
end
|