listen 0.4.7 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +161 -147
- data/LICENSE +20 -20
- data/README.md +2 -3
- data/lib/listen.rb +6 -5
- data/lib/listen/adapter.rb +72 -27
- data/lib/listen/adapters/darwin.rb +11 -10
- data/lib/listen/adapters/linux.rb +33 -30
- data/lib/listen/adapters/polling.rb +1 -0
- data/lib/listen/adapters/windows.rb +27 -21
- data/lib/listen/dependency_manager.rb +126 -0
- data/lib/listen/directory_record.rb +318 -318
- data/lib/listen/listener.rb +203 -203
- data/lib/listen/multi_listener.rb +121 -121
- data/lib/listen/turnstile.rb +28 -28
- data/lib/listen/version.rb +3 -3
- metadata +14 -57
data/CHANGELOG.md
CHANGED
@@ -1,147 +1,161 @@
|
|
1
|
-
## 0.
|
2
|
-
|
3
|
-
###
|
4
|
-
|
5
|
-
-
|
6
|
-
|
7
|
-
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
- [#
|
20
|
-
|
21
|
-
## 0.4.
|
22
|
-
|
23
|
-
### Bug
|
24
|
-
|
25
|
-
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
###
|
36
|
-
|
37
|
-
-
|
38
|
-
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
- [#
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
## 0.3.
|
97
|
-
|
98
|
-
###
|
99
|
-
|
100
|
-
-
|
101
|
-
|
102
|
-
## 0.3.
|
103
|
-
|
104
|
-
### New
|
105
|
-
|
106
|
-
- Add
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
[
|
126
|
-
[
|
127
|
-
[
|
128
|
-
[
|
129
|
-
[
|
130
|
-
[
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
[@
|
135
|
-
|
136
|
-
|
137
|
-
[
|
138
|
-
[
|
139
|
-
[
|
140
|
-
[
|
141
|
-
[
|
142
|
-
[
|
143
|
-
[
|
144
|
-
[
|
145
|
-
[
|
146
|
-
[@
|
147
|
-
[@
|
1
|
+
## 0.5.0 - Septemper 1, 2012
|
2
|
+
|
3
|
+
### New features
|
4
|
+
|
5
|
+
- Add a dependency manager to handle platform-specific gems. So there is no need anymore to install
|
6
|
+
extra gems which will never be used on the user system. ([@Maher4Ever][])
|
7
|
+
- Add a manual reporting mode to the adapters. ([@Maher4Ever][])
|
8
|
+
|
9
|
+
### Improvements
|
10
|
+
|
11
|
+
- [#28] Enhance the speed of detecting changes on Windows by using the [WDM][] library. ([@Maher4Ever][])
|
12
|
+
|
13
|
+
## 0.4.7 - June 27, 2012
|
14
|
+
|
15
|
+
### Bug fixes
|
16
|
+
|
17
|
+
- Increase latency to 0.25, to avoid useless polling fallback. (fixed by [@thibaudgg][])
|
18
|
+
- Change watched inotify events, to avoid duplication callback. (fixed by [@thibaudgg][])
|
19
|
+
- [#41](https://github.com/guard/listen/issues/41) Use lstat instead of stat when calculating mtime. (fixed by [@ebroder][])
|
20
|
+
|
21
|
+
## 0.4.6 - June 20, 2012
|
22
|
+
|
23
|
+
### Bug fix
|
24
|
+
|
25
|
+
- [#39](https://github.com/guard/listen/issues/39) Fix digest race condition. (fixed by [@dkubb][])
|
26
|
+
|
27
|
+
## 0.4.5 - June 13, 2012
|
28
|
+
|
29
|
+
### Bug fix
|
30
|
+
|
31
|
+
- [#39](https://github.com/guard/listen/issues/39) Rescue Errno::ENOENT when path inserted doesn't exist. (reported by [@textgoeshere][], fixed by [@thibaudgg][] and [@rymai][])
|
32
|
+
|
33
|
+
## 0.4.4 - June 8, 2012
|
34
|
+
|
35
|
+
### Bug fixes
|
36
|
+
|
37
|
+
- ~~[#39](https://github.com/guard/listen/issues/39) Non-existing path insertion bug. (reported by [@textgoeshere][], fixed by [@thibaudgg][])~~
|
38
|
+
- Fix relative path for directories containing special characters. (reported by [@napcs][], fixed by [@netzpirat][])
|
39
|
+
|
40
|
+
## 0.4.3 - June 6, 2012
|
41
|
+
|
42
|
+
### Bug fixes
|
43
|
+
|
44
|
+
- [#24](https://github.com/guard/listen/issues/24) Fail gracefully when the inotify limit is not enough for Listen to function. (reported by [@daemonza][], fixed by [@Maher4Ever][])
|
45
|
+
- [#32](https://github.com/guard/listen/issues/32) Fix a crash when trying to calculate the checksum of unreadable files. (reported by [@nex3][], fixed by [@Maher4Ever][])
|
46
|
+
|
47
|
+
### Improvements
|
48
|
+
|
49
|
+
- Add `#relative_paths` method to listeners. ([@Maher4Ever][])
|
50
|
+
- Add `#started?` query-method to adapters. ([@Maher4Ever][])
|
51
|
+
- Dynamically detect the mtime precision used on a system. ([@Maher4Ever][] with help from [@nex3][])
|
52
|
+
|
53
|
+
## 0.4.2 - May 1, 2012
|
54
|
+
|
55
|
+
### Bug fixes
|
56
|
+
|
57
|
+
- [#21](https://github.com/guard/listen/issues/21) Issues when listening to changes in relative paths. (reported by [@akerbos][], fixed by [@Maher4Ever][])
|
58
|
+
- [#27](https://github.com/guard/listen/issues/27) Wrong reports for files modifications. (reported by [@cobychapple][], fixed by [@Maher4Ever][])
|
59
|
+
- Fix segmentation fault when profiling on Windows. ([@Maher4Ever][])
|
60
|
+
- Fix redundant watchers on Windows. ([@Maher4Ever][])
|
61
|
+
|
62
|
+
### Improvements
|
63
|
+
|
64
|
+
- [#17](https://github.com/guard/listen/issues/17) Use regexp-patterns with the `ignore` method instead of supplying paths. (reported by [@fny][], added by [@Maher4Ever][])
|
65
|
+
- Speed improvement when listening to changes in directories with ignored paths. ([@Maher4Ever][])
|
66
|
+
- Added `.rbx` and `.svn` to ignored directories. ([@Maher4Ever][])
|
67
|
+
|
68
|
+
## 0.4.1 - April 15, 2012
|
69
|
+
|
70
|
+
### Bug fix
|
71
|
+
|
72
|
+
- [#18](https://github.com/guard/listen/issues/18) Listener crashes when removing directories with nested paths. (reported by [@daemonza][], fixed by [@Maher4Ever][])
|
73
|
+
|
74
|
+
## 0.4.0 - April 9, 2012
|
75
|
+
|
76
|
+
### New features
|
77
|
+
|
78
|
+
- Add `wait_for_callback` method to all adapters. ([@Maher4Ever][])
|
79
|
+
- Add `Listen::MultiListener` class to listen to multiple directories at once. ([@Maher4Ever][])
|
80
|
+
- Allow passing multiple directories to the `Listen.to` method. ([@Maher4Ever][])
|
81
|
+
- Add `blocking` option to `Listen#start` which can be used to disable blocking the current thread upon starting. ([@Maher4Ever][])
|
82
|
+
- Use absolute-paths in callbacks by default instead of relative-paths. ([@Maher4Ever][])
|
83
|
+
- Add `relative_paths` option to `Listen::Listener` to retain the old functionality. ([@Maher4Ever][])
|
84
|
+
|
85
|
+
### Improvements
|
86
|
+
|
87
|
+
- Encapsulate thread spawning in the linux-adapter. ([@Maher4Ever][])
|
88
|
+
- Encapsulate thread spawning in the darwin-adapter. ([@Maher4Ever][] with [@scottdavis][] help)
|
89
|
+
- Encapsulate thread spawning in the windows-adapter. ([@Maher4Ever][])
|
90
|
+
- Fix linux-adapter bug where Listen would report file-modification events on the parent-directory. ([@Maher4Ever][])
|
91
|
+
|
92
|
+
### Change
|
93
|
+
|
94
|
+
- Remove `wait_until_listening` as adapters doesn't need to run inside threads anymore ([@Maher4Ever][])
|
95
|
+
|
96
|
+
## 0.3.3 - March 6, 2012
|
97
|
+
|
98
|
+
### Improvement
|
99
|
+
|
100
|
+
- Improve pause/unpause. ([@thibaudgg][])
|
101
|
+
|
102
|
+
## 0.3.2 - March 4, 2012
|
103
|
+
|
104
|
+
### New feature
|
105
|
+
|
106
|
+
- Add pause/unpause listener's methods. ([@thibaudgg][])
|
107
|
+
|
108
|
+
## 0.3.1 - February 22, 2012
|
109
|
+
|
110
|
+
### Bug fix
|
111
|
+
|
112
|
+
- [#9](https://github.com/guard/listen/issues/9) Ignore doesn't seem to work. (reported by [@markiz][], fixed by [@thibaudgg][])
|
113
|
+
|
114
|
+
## 0.3.0 - February 21, 2012
|
115
|
+
|
116
|
+
### New features
|
117
|
+
|
118
|
+
- Add automatic fallback to polling if system adapter doesn't work (like a DropBox folder). ([@thibaudgg][])
|
119
|
+
- Add latency and force_polling options. ([@Maher4Ever][])
|
120
|
+
|
121
|
+
## 0.2.0 - February 13, 2012
|
122
|
+
|
123
|
+
### New features
|
124
|
+
|
125
|
+
- Add checksum comparaison support for detecting consecutive file modifications made during the same second. ([@thibaudgg][])
|
126
|
+
- Add rb-fchange support. ([@thibaudgg][])
|
127
|
+
- Add rb-inotify support. ([@thibaudgg][] with [@Maher4Ever][] help)
|
128
|
+
- Add rb-fsevent support. ([@thibaudgg][])
|
129
|
+
- Add non-recursive diff with multiple directories support. ([@thibaudgg][])
|
130
|
+
- Ignore .DS_Store by default. ([@thibaudgg][])
|
131
|
+
|
132
|
+
## 0.1.0 - January 28, 2012
|
133
|
+
|
134
|
+
- First version with only a polling adapter and basic features set (ignore & filter). ([@thibaudgg][])
|
135
|
+
|
136
|
+
<!--- The following link definition list is generated by PimpMyChangelog --->
|
137
|
+
[#9]: https://github.com/guard/listen/issues/9
|
138
|
+
[#17]: https://github.com/guard/listen/issues/17
|
139
|
+
[#18]: https://github.com/guard/listen/issues/18
|
140
|
+
[#21]: https://github.com/guard/listen/issues/21
|
141
|
+
[#24]: https://github.com/guard/listen/issues/24
|
142
|
+
[#27]: https://github.com/guard/listen/issues/27
|
143
|
+
[#28]: https://github.com/guard/listen/issues/28
|
144
|
+
[#32]: https://github.com/guard/listen/issues/32
|
145
|
+
[#39]: https://github.com/guard/listen/issues/39
|
146
|
+
[@Maher4Ever]: https://github.com/Maher4Ever
|
147
|
+
[@dkubb]: https://github.com/dkubb
|
148
|
+
[@ebroder]: https://github.com/ebroder
|
149
|
+
[@akerbos]: https://github.com/akerbos
|
150
|
+
[@cobychapple]: https://github.com/cobychapple
|
151
|
+
[@daemonza]: https://github.com/daemonza
|
152
|
+
[@fny]: https://github.com/fny
|
153
|
+
[@markiz]: https://github.com/markiz
|
154
|
+
[@napcs]: https://github.com/napcs
|
155
|
+
[@netzpirat]: https://github.com/netzpirat
|
156
|
+
[@nex3]: https://github.com/nex3
|
157
|
+
[@rymai]: https://github.com/rymai
|
158
|
+
[@scottdavis]: https://github.com/scottdavis
|
159
|
+
[@textgoeshere]: https://github.com/textgoeshere
|
160
|
+
[@thibaudgg]: https://github.com/thibaudgg
|
161
|
+
[WDM]: https://github.com/Maher4Ever/wdm
|
data/LICENSE
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
Copyright (c) 2012 Thibaud Guillaume-Gentil
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
Copyright (c) 2012 Thibaud Guillaume-Gentil
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -8,8 +8,8 @@ The Listen gem listens to file modifications and notifies you about the changes.
|
|
8
8
|
* Supports watching multiple directories from a single listener.
|
9
9
|
* OS-specific adapters for Mac OS X 10.6+, Linux and Windows.
|
10
10
|
* Automatic fallback to polling if OS-specific adapter doesn't work.
|
11
|
-
* Detects
|
12
|
-
* Checksum
|
11
|
+
* Detects file modification, addition and removal.
|
12
|
+
* Checksum comparison for modifications made under the same second.
|
13
13
|
* Allows supplying regexp-patterns to ignore and filter paths for better results.
|
14
14
|
* Tested on all Ruby environments via [travis-ci](http://travis-ci.org/guard/listen).
|
15
15
|
|
@@ -251,7 +251,6 @@ want to force the use of the polling adapter, either use the `:force_polling` op
|
|
251
251
|
while initializing the listener or call the `force_polling` method on your listener
|
252
252
|
before starting it.
|
253
253
|
|
254
|
-
<a name="fallback"/>
|
255
254
|
## Polling fallback
|
256
255
|
|
257
256
|
When a OS-specific adapter doesn't work the Listen gem automatically falls back to the polling adapter.
|
data/lib/listen.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
module Listen
|
2
2
|
|
3
|
-
autoload :Turnstile,
|
4
|
-
autoload :Listener,
|
5
|
-
autoload :MultiListener,
|
6
|
-
autoload :DirectoryRecord,
|
7
|
-
autoload :
|
3
|
+
autoload :Turnstile, 'listen/turnstile'
|
4
|
+
autoload :Listener, 'listen/listener'
|
5
|
+
autoload :MultiListener, 'listen/multi_listener'
|
6
|
+
autoload :DirectoryRecord, 'listen/directory_record'
|
7
|
+
autoload :DependencyManager, 'listen/dependency_manager'
|
8
|
+
autoload :Adapter, 'listen/adapter'
|
8
9
|
|
9
10
|
module Adapters
|
10
11
|
autoload :Darwin, 'listen/adapters/darwin'
|
data/lib/listen/adapter.rb
CHANGED
@@ -10,8 +10,15 @@ module Listen
|
|
10
10
|
# The default delay between checking for changes.
|
11
11
|
DEFAULT_LATENCY = 0.25
|
12
12
|
|
13
|
+
# The default warning message when there is a missing dependency.
|
14
|
+
MISSING_DEPENDENCY_MESSAGE = <<-EOS.gsub(/^\s*/, '')
|
15
|
+
For a better performance, it's recommended that you satisfy the missing dependency.
|
16
|
+
EOS
|
17
|
+
|
13
18
|
# The default warning message when falling back to polling adapter.
|
14
|
-
POLLING_FALLBACK_MESSAGE =
|
19
|
+
POLLING_FALLBACK_MESSAGE = <<-EOS.gsub(/^\s*/, '')
|
20
|
+
Listen will be polling changes. Learn more at https://github.com/guard/listen#polling-fallback.
|
21
|
+
EOS
|
15
22
|
|
16
23
|
# Selects the appropriate adapter implementation for the
|
17
24
|
# current OS and initializes it.
|
@@ -31,18 +38,26 @@ module Listen
|
|
31
38
|
def self.select_and_initialize(directories, options = {}, &callback)
|
32
39
|
return Adapters::Polling.new(directories, options, &callback) if options.delete(:force_polling)
|
33
40
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
Adapters::
|
38
|
-
|
39
|
-
Adapters::
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
warning = ''
|
42
|
+
|
43
|
+
begin
|
44
|
+
if Adapters::Darwin.usable_and_works?(directories, options)
|
45
|
+
return Adapters::Darwin.new(directories, options, &callback)
|
46
|
+
elsif Adapters::Linux.usable_and_works?(directories, options)
|
47
|
+
return Adapters::Linux.new(directories, options, &callback)
|
48
|
+
elsif Adapters::Windows.usable_and_works?(directories, options)
|
49
|
+
return Adapters::Windows.new(directories, options, &callback)
|
43
50
|
end
|
44
|
-
|
51
|
+
rescue DependencyManager::Error => e
|
52
|
+
warning += e.message + "\n" + MISSING_DEPENDENCY_MESSAGE
|
53
|
+
end
|
54
|
+
|
55
|
+
unless options[:polling_fallback_message] == false
|
56
|
+
warning += options[:polling_fallback_message] || POLLING_FALLBACK_MESSAGE
|
57
|
+
Kernel.warn "[Listen warning]:\n" + warning.gsub(/^(.*)/, ' \1')
|
45
58
|
end
|
59
|
+
|
60
|
+
Adapters::Polling.new(directories, options, &callback)
|
46
61
|
end
|
47
62
|
|
48
63
|
# Initializes the adapter.
|
@@ -50,6 +65,7 @@ module Listen
|
|
50
65
|
# @param [String, Array<String>] directories the directories to watch
|
51
66
|
# @param [Hash] options the adapter options
|
52
67
|
# @option options [Float] latency the delay between checking for changes in seconds
|
68
|
+
# @option options [Boolean] report_changes whether or not to automatically report changes (run the callback)
|
53
69
|
#
|
54
70
|
# @yield [changed_dirs, options] callback Callback called when a change happens
|
55
71
|
# @yieldparam [Array<String>] changed_dirs the changed directories
|
@@ -60,12 +76,13 @@ module Listen
|
|
60
76
|
def initialize(directories, options = {}, &callback)
|
61
77
|
@directories = Array(directories)
|
62
78
|
@callback = callback
|
63
|
-
@latency ||= DEFAULT_LATENCY
|
64
|
-
@latency = options[:latency] if options[:latency]
|
65
79
|
@paused = false
|
66
80
|
@mutex = Mutex.new
|
67
81
|
@changed_dirs = Set.new
|
68
82
|
@turnstile = Turnstile.new
|
83
|
+
@latency ||= DEFAULT_LATENCY
|
84
|
+
@latency = options[:latency] if options[:latency]
|
85
|
+
@report_changes = options[:report_changes].nil? ? true : options[:report_changes]
|
69
86
|
end
|
70
87
|
|
71
88
|
# Starts the adapter.
|
@@ -92,12 +109,37 @@ module Listen
|
|
92
109
|
end
|
93
110
|
|
94
111
|
# Blocks the main thread until the poll thread
|
95
|
-
#
|
112
|
+
# runs the callback.
|
96
113
|
#
|
97
114
|
def wait_for_callback
|
98
115
|
@turnstile.wait unless @paused
|
99
116
|
end
|
100
117
|
|
118
|
+
# Blocks the main thread until N changes are
|
119
|
+
# detected.
|
120
|
+
#
|
121
|
+
def wait_for_changes(goal = 0)
|
122
|
+
changes = 0
|
123
|
+
|
124
|
+
loop do
|
125
|
+
@mutex.synchronize { changes = @changed_dirs.size }
|
126
|
+
|
127
|
+
return if @paused || @stop
|
128
|
+
return if changes >= goal
|
129
|
+
|
130
|
+
sleep(@latency)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
# Checks if the adapter is usable on the current OS.
|
135
|
+
#
|
136
|
+
# @return [Boolean] whether usable or not
|
137
|
+
#
|
138
|
+
def self.usable?
|
139
|
+
load_depenencies
|
140
|
+
dependencies_loaded?
|
141
|
+
end
|
142
|
+
|
101
143
|
# Checks if the adapter is usable and works on the current OS.
|
102
144
|
#
|
103
145
|
# @param [String, Array<String>] directories the directories to watch
|
@@ -140,26 +182,29 @@ module Listen
|
|
140
182
|
adapter.stop if adapter && adapter.started?
|
141
183
|
end
|
142
184
|
|
185
|
+
# Runs the callback and passes it the changes if there are any.
|
186
|
+
#
|
187
|
+
def report_changes
|
188
|
+
changed_dirs = nil
|
189
|
+
|
190
|
+
@mutex.synchronize do
|
191
|
+
return if @changed_dirs.empty?
|
192
|
+
changed_dirs = @changed_dirs.to_a
|
193
|
+
@changed_dirs.clear
|
194
|
+
end
|
195
|
+
|
196
|
+
@callback.call(changed_dirs, {})
|
197
|
+
end
|
198
|
+
|
143
199
|
private
|
144
200
|
|
145
201
|
# Polls changed directories and reports them back
|
146
202
|
# when there are changes.
|
147
203
|
#
|
148
|
-
|
149
|
-
#
|
150
|
-
def poll_changed_dirs(recursive = false)
|
204
|
+
def poll_changed_dirs
|
151
205
|
until @stop
|
152
206
|
sleep(@latency)
|
153
|
-
|
154
|
-
|
155
|
-
changed_dirs = []
|
156
|
-
|
157
|
-
@mutex.synchronize do
|
158
|
-
changed_dirs = @changed_dirs.to_a
|
159
|
-
@changed_dirs.clear
|
160
|
-
end
|
161
|
-
|
162
|
-
@callback.call(changed_dirs, recursive ? {:recursive => recursive} : {})
|
207
|
+
report_changes
|
163
208
|
@turnstile.signal
|
164
209
|
end
|
165
210
|
end
|