listen 0.4.7 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,147 +1,161 @@
1
- ## 0.4.7 - June 27, 2012
2
-
3
- ### Bug fixes
4
-
5
- - Increase latency to 0.25, to avoid useless polling fallback. (fixed by [@thibaudgg][])
6
- - Change watched inotify events, to avoid duplication callback. (fixed by [@thibaudgg][])
7
- - [#41](https://github.com/guard/listen/issues/41) Use lstat instead of stat when calculating mtime. (fixed by [@ebroder][])
8
-
9
- ## 0.4.6 - June 20, 2012
10
-
11
- ### Bug fix
12
-
13
- - [#39](https://github.com/guard/listen/issues/39) Fix digest race condition. (fixed by [@dkubb][])
14
-
15
- ## 0.4.5 - June 13, 2012
16
-
17
- ### Bug fix
18
-
19
- - [#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][])
20
-
21
- ## 0.4.4 - June 8, 2012
22
-
23
- ### Bug fixes
24
-
25
- - ~~[#39](https://github.com/guard/listen/issues/39) Non-existing path insertion bug. (reported by [@textgoeshere][], fixed by [@thibaudgg][])~~
26
- - Fix relative path for directories containing special characters. (reported by [@napcs][], fixed by [@netzpirat][])
27
-
28
- ## 0.4.3 - June 6, 2012
29
-
30
- ### Bug fixes
31
-
32
- - [#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][])
33
- - [#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][])
34
-
35
- ### Improvements
36
-
37
- - Add `#relative_paths` method to listeners. ([@Maher4Ever][])
38
- - Add `#started?` query-method to adapters. ([@Maher4Ever][])
39
- - Dynamically detect the mtime precision used on a system. ([@Maher4Ever][] with help from [@nex3][])
40
-
41
- ## 0.4.2 - May 1, 2012
42
-
43
- ### Bug fixes
44
-
45
- - [#21](https://github.com/guard/listen/issues/21) Issues when listening to changes in relative paths. (reported by [@akerbos][], fixed by [@Maher4Ever][])
46
- - [#27](https://github.com/guard/listen/issues/27) Wrong reports for files modifications. (reported by [@cobychapple][], fixed by [@Maher4Ever][])
47
- - Fix segmentation fault when profiling on Windows. ([@Maher4Ever][])
48
- - Fix redundant watchers on Windows. ([@Maher4Ever][])
49
-
50
- ### Improvements
51
-
52
- - [#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][])
53
- - Speed improvement when listening to changes in directories with ignored paths. ([@Maher4Ever][])
54
- - Added `.rbx` and `.svn` to ignored directories. ([@Maher4Ever][])
55
-
56
- ## 0.4.1 - April 15, 2012
57
-
58
- ### Bug fix
59
-
60
- - [#18](https://github.com/guard/listen/issues/18) Listener crashes when removing directories with nested paths. (reported by [@daemonza][], fixed by [@Maher4Ever][])
61
-
62
- ## 0.4.0 - April 9, 2012
63
-
64
- ### New features
65
-
66
- - Add `wait_for_callback` method to all adapters. ([@Maher4Ever][])
67
- - Add `Listen::MultiListener` class to listen to multiple directories at once. ([@Maher4Ever][])
68
- - Allow passing multiple directories to the `Listen.to` method. ([@Maher4Ever][])
69
- - Add `blocking` option to `Listen#start` which can be used to disable blocking the current thread upon starting. ([@Maher4Ever][])
70
- - Use absolute-paths in callbacks by default instead of relative-paths. ([@Maher4Ever][])
71
- - Add `relative_paths` option to `Listen::Listener` to retain the old functionality. ([@Maher4Ever][])
72
-
73
- ### Improvements
74
-
75
- - Encapsulate thread spawning in the linux-adapter. ([@Maher4Ever][])
76
- - Encapsulate thread spawning in the darwin-adapter. ([@Maher4Ever][] with [@scottdavis][] help)
77
- - Encapsulate thread spawning in the windows-adapter. ([@Maher4Ever][])
78
- - Fix linux-adapter bug where Listen would report file-modification events on the parent-directory. ([@Maher4Ever][])
79
-
80
- ### Change
81
-
82
- - Remove `wait_until_listening` as adapters doesn't need to run inside threads anymore ([@Maher4Ever][])
83
-
84
- ## 0.3.3 - March 6, 2012
85
-
86
- ### Improvement
87
-
88
- - Improve pause/unpause. ([@thibaudgg][])
89
-
90
- ## 0.3.2 - March 4, 2012
91
-
92
- ### New feature
93
-
94
- - Add pause/unpause listener's methods. ([@thibaudgg][])
95
-
96
- ## 0.3.1 - February 22, 2012
97
-
98
- ### Bug fix
99
-
100
- - [#9](https://github.com/guard/listen/issues/9) Ignore doesn't seem to work. (reported by [@markiz][], fixed by [@thibaudgg][])
101
-
102
- ## 0.3.0 - February 21, 2012
103
-
104
- ### New features
105
-
106
- - Add automatic fallback to polling if system adapter doesn't work (like a DropBox folder). ([@thibaudgg][])
107
- - Add latency and force_polling options. ([@Maher4Ever][])
108
-
109
- ## 0.2.0 - February 13, 2012
110
-
111
- ### New features
112
-
113
- - Add checksum comparaison support for detecting consecutive file modifications made during the same second. ([@thibaudgg][])
114
- - Add rb-fchange support. ([@thibaudgg][])
115
- - Add rb-inotify support. ([@thibaudgg][] with [@Maher4Ever][] help)
116
- - Add rb-fsevent support. ([@thibaudgg][])
117
- - Add non-recursive diff with multiple directories support. ([@thibaudgg][])
118
- - Ignore .DS_Store by default. ([@thibaudgg][])
119
-
120
- ## 0.1.0 - January 28, 2012
121
-
122
- - First version with only a polling adapter and basic features set (ignore & filter). ([@thibaudgg][])
123
-
124
- <!--- The following link definition list is generated by PimpMyChangelog --->
125
- [#9]: https://github.com/guard/listen/issues/9
126
- [#17]: https://github.com/guard/listen/issues/17
127
- [#18]: https://github.com/guard/listen/issues/18
128
- [#21]: https://github.com/guard/listen/issues/21
129
- [#24]: https://github.com/guard/listen/issues/24
130
- [#27]: https://github.com/guard/listen/issues/27
131
- [#32]: https://github.com/guard/listen/issues/32
132
- [#39]: https://github.com/guard/listen/issues/39
133
- [@Maher4Ever]: https://github.com/Maher4Ever
134
- [@dkubb]: https://github.com/dkubb
135
- [@ebroder]: https://github.com/ebroder
136
- [@akerbos]: https://github.com/akerbos
137
- [@cobychapple]: https://github.com/cobychapple
138
- [@daemonza]: https://github.com/daemonza
139
- [@fny]: https://github.com/fny
140
- [@markiz]: https://github.com/markiz
141
- [@napcs]: https://github.com/napcs
142
- [@netzpirat]: https://github.com/netzpirat
143
- [@nex3]: https://github.com/nex3
144
- [@rymai]: https://github.com/rymai
145
- [@scottdavis]: https://github.com/scottdavis
146
- [@textgoeshere]: https://github.com/textgoeshere
147
- [@thibaudgg]: https://github.com/thibaudgg
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 files modification, addidation and removal.
12
- * Checksum comparaison for modifications made under the same second.
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.
@@ -1,10 +1,11 @@
1
1
  module Listen
2
2
 
3
- autoload :Turnstile, 'listen/turnstile'
4
- autoload :Listener, 'listen/listener'
5
- autoload :MultiListener, 'listen/multi_listener'
6
- autoload :DirectoryRecord, 'listen/directory_record'
7
- autoload :Adapter, 'listen/adapter'
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'
@@ -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 = "WARNING: Listen has fallen back to polling, learn more at https://github.com/guard/listen#fallback."
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
- if Adapters::Darwin.usable_and_works?(directories, options)
35
- Adapters::Darwin.new(directories, options, &callback)
36
- elsif Adapters::Linux.usable_and_works?(directories, options)
37
- Adapters::Linux.new(directories, options, &callback)
38
- elsif Adapters::Windows.usable_and_works?(directories, options)
39
- Adapters::Windows.new(directories, options, &callback)
40
- else
41
- unless options[:polling_fallback_message] == false
42
- Kernel.warn(options[:polling_fallback_message] || POLLING_FALLBACK_MESSAGE)
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
- Adapters::Polling.new(directories, options, &callback)
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
- # calls the callback.
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
- # @option [Boolean] recursive whether or not to pass the recursive option to the callback
149
- #
150
- def poll_changed_dirs(recursive = false)
204
+ def poll_changed_dirs
151
205
  until @stop
152
206
  sleep(@latency)
153
- next if @changed_dirs.empty?
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