driskell-listen 3.0.6.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +1 -0
  3. data/CONTRIBUTING.md +38 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +293 -0
  6. data/bin/driskell-listen +12 -0
  7. data/lib/driskell-listen.rb +61 -0
  8. data/lib/driskell-listen/adapter.rb +44 -0
  9. data/lib/driskell-listen/adapter/base.rb +147 -0
  10. data/lib/driskell-listen/adapter/bsd.rb +106 -0
  11. data/lib/driskell-listen/adapter/config.rb +26 -0
  12. data/lib/driskell-listen/adapter/darwin.rb +71 -0
  13. data/lib/driskell-listen/adapter/linux.rb +96 -0
  14. data/lib/driskell-listen/adapter/polling.rb +37 -0
  15. data/lib/driskell-listen/adapter/simulated_darwin.rb +65 -0
  16. data/lib/driskell-listen/adapter/windows.rb +99 -0
  17. data/lib/driskell-listen/backend.rb +45 -0
  18. data/lib/driskell-listen/change.rb +80 -0
  19. data/lib/driskell-listen/cli.rb +65 -0
  20. data/lib/driskell-listen/directory.rb +83 -0
  21. data/lib/driskell-listen/event/config.rb +59 -0
  22. data/lib/driskell-listen/event/loop.rb +117 -0
  23. data/lib/driskell-listen/event/processor.rb +122 -0
  24. data/lib/driskell-listen/event/queue.rb +56 -0
  25. data/lib/driskell-listen/file.rb +80 -0
  26. data/lib/driskell-listen/fsm.rb +131 -0
  27. data/lib/driskell-listen/internals/thread_pool.rb +21 -0
  28. data/lib/driskell-listen/listener.rb +132 -0
  29. data/lib/driskell-listen/listener/config.rb +45 -0
  30. data/lib/driskell-listen/logger.rb +32 -0
  31. data/lib/driskell-listen/options.rb +23 -0
  32. data/lib/driskell-listen/queue_optimizer.rb +132 -0
  33. data/lib/driskell-listen/record.rb +104 -0
  34. data/lib/driskell-listen/record/entry.rb +56 -0
  35. data/lib/driskell-listen/silencer.rb +97 -0
  36. data/lib/driskell-listen/silencer/controller.rb +48 -0
  37. data/lib/driskell-listen/version.rb +5 -0
  38. metadata +126 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1b754e9ebee0d0d18528b37fce13049f588fcd6b
4
+ data.tar.gz: a60593e7ee856b6b283c3745581efd3a6c6d7d6c
5
+ SHA512:
6
+ metadata.gz: 45d904cf82eb65198fa77a329dfcec72605c88bcabdd7adfff755e2e10b39bab31b5969296cc4b6520d958be335d448d5252a36f53a5bdfcceada4be641d7251
7
+ data.tar.gz: f979e13bfd024ebaff176e4079af627d8e3fdb0821040d35ebee7a05823f07ae242712c6f3db293e53ea90e2438087c15b7c5d3d6f59fdc75c950cfc8c588c49
@@ -0,0 +1 @@
1
+ # Moved to [GitHub releases](https://github.com/guard/listen/releases) page.
@@ -0,0 +1,38 @@
1
+ Contribute to Listen
2
+ ===================
3
+
4
+ File an issue
5
+ -------------
6
+
7
+ If you haven't already, first see [TROUBLESHOOTING](https://github.com/guard/listen/wiki/Troubleshooting) for known issues, solutions and workarounds.
8
+
9
+ You can report bugs and feature requests to [GitHub Issues](https://github.com/guard/listen/issues).
10
+
11
+ **Please don't ask question in the issue tracker**, instead ask them in our
12
+ [Google group](http://groups.google.com/group/guard-dev) or on `#guard` (irc.freenode.net).
13
+
14
+ Try to figure out where the issue belongs to: Is it an issue with Listen itself or with Guard?
15
+
16
+
17
+ **It's most likely that your bug gets resolved faster if you provide as much information as possible!**
18
+
19
+ The MOST useful information is debugging output from Listen (`LISTEN_GEM_DEBUGGING=1`) - see [TROUBLESHOOTING](https://github.com/guard/listen/wiki/Troubleshooting) for details.
20
+
21
+
22
+ Development
23
+ -----------
24
+
25
+ * Documentation hosted at [RubyDoc](http://rubydoc.info/github/guard/listen/master/frames).
26
+ * Source hosted at [GitHub](https://github.com/guard/listen).
27
+
28
+ Pull requests are very welcome! Please try to follow these simple rules if applicable:
29
+
30
+ * Please create a topic branch for every separate change you make.
31
+ * Make sure your patches are well tested. All specs run with `rake spec` must pass.
32
+ * Update the [Yard](http://yardoc.org/) documentation.
33
+ * Update the [README](https://github.com/guard/listen/blob/master/README.md).
34
+ * Update the [CHANGELOG](https://github.com/guard/listen/blob/master/CHANGELOG.md) for noteworthy changes.
35
+ * Please **do not change** the version number.
36
+
37
+ For questions please join us in our [Google group](http://groups.google.com/group/guard-dev) or on
38
+ `#guard` (irc.freenode.net).
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Thibaud Guillaume-Gentil
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,293 @@
1
+ :exclamation: Listen is currently accepting more maintainers. Please [read this](https://github.com/guard/guard/wiki/Maintainers) if you're interested in joining the team.
2
+
3
+ # Listen
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/listen.png)](http://badge.fury.io/rb/listen) [![Build Status](https://travis-ci.org/guard/listen.png)](https://travis-ci.org/guard/listen) [![Dependency Status](https://gemnasium.com/guard/listen.png)](https://gemnasium.com/guard/listen) [![Code Climate](https://codeclimate.com/github/guard/listen.png)](https://codeclimate.com/github/guard/listen) [![Coverage Status](https://coveralls.io/repos/guard/listen/badge.png?branch=master)](https://coveralls.io/r/guard/listen)
6
+
7
+ The Listen gem listens to file modifications and notifies you about the changes.
8
+
9
+ ## Features
10
+
11
+ * OS-optimized adapters on MRI for Mac OS X 10.6+, Linux, \*BSD and Windows, [more info](#listen-adapters) below.
12
+ * Detects file modification, addition and removal.
13
+ * You can watch multiple directories.
14
+ * Regexp-patterns for ignoring paths for more accuracy and speed
15
+ * Increased change detection accuracy on OS X HFS and VFAT volumes.
16
+ * Tested on MRI Ruby environments (2.0+ only) via [Travis CI](https://travis-ci.org/guard/listen),
17
+
18
+ ## Issues / limitations
19
+
20
+ * Limited support for symlinked directories ([#279](https://github.com/guard/listen/issues/279)):
21
+ * Symlinks are always followed ([#25](https://github.com/guard/listen/issues/25)).
22
+ * Symlinked directories pointing within a watched directory are not supported ([#273](https://github.com/guard/listen/pull/273)- see [Duplicate directory errors](https://github.com/guard/listen/wiki/Duplicate-directory-errors)).
23
+ * No directory/adapter-specific configuration options.
24
+ * Support for plugins planned for future.
25
+ * TCP functionality was removed in Listen [3.0.0](https://github.com/guard/listen/releases/tag/v3.0.0) ([#319](https://github.com/guard/listen/issues/319), [#218](https://github.com/guard/listen/issues/218)). There are plans to extract this feature to separate gems ([#258](https://github.com/guard/listen/issues/258)), until this is finished, you can use by locking the `listen` gem to version `'~> 2.10'`.
26
+ * Some filesystems won't work without polling (VM/Vagrant Shared folders, NFS, Samba, sshfs, etc.).
27
+ * Specs suite on JRuby and Rubinius aren't reliable on Travis CI, but should work.
28
+ * Windows and \*BSD adapter aren't continuously and automatically tested.
29
+ * OSX adapter has some performance limitations ([#342](https://github.com/guard/listen/issues/342)).
30
+ * Ruby 1.9.3 is no longer maintained (and may not work with Listen) - it's best to upgrade to Ruby 2.2.2.
31
+
32
+ Pull requests or help is very welcome for these.
33
+
34
+ ## Install
35
+
36
+ The simplest way to install Listen is to use [Bundler](http://bundler.io).
37
+
38
+ ```ruby
39
+ gem 'listen', '~> 3.0' # NOTE: for TCP functionality, use '~> 2.10' for now
40
+ ```
41
+
42
+ ## Usage
43
+
44
+ Call `Listen.to` with either a single directory or multiple directories, then define the "changes" callback in a block.
45
+
46
+ ``` ruby
47
+ listener = Listen.to('dir/to/listen', 'dir/to/listen2') do |modified, added, removed|
48
+ puts "modified absolute path: #{modified}"
49
+ puts "added absolute path: #{added}"
50
+ puts "removed absolute path: #{removed}"
51
+ end
52
+ listener.start # not blocking
53
+ sleep
54
+ ```
55
+
56
+ ### Pause / unpause / stop
57
+
58
+ Listeners can also be easily paused/unpaused:
59
+
60
+ ``` ruby
61
+ listener = Listen.to('dir/path/to/listen') { |modified, added, removed| puts 'handle changes here...' }
62
+
63
+ listener.start
64
+ listener.paused? # => false
65
+ listener.processing? # => true
66
+
67
+ listener.pause # stops processing changes (but keeps on collecting them)
68
+ listener.paused? # => true
69
+ listener.processing? # => false
70
+
71
+ listener.unpause # resumes processing changes ("start" would do the same)
72
+ listener.stop # stop both listening to changes and processing them
73
+ ```
74
+
75
+ Note: While paused, Listen keeps on collecting changes in the background - to clear them, call "stop"
76
+
77
+ Note: You should keep track of all started listeners and stop them properly on finish.
78
+
79
+ ### Ignore / ignore!
80
+
81
+ Listen ignores some directories and extensions by default (See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer), you can add ignoring patterns with the `ignore` option/method or overwrite default with `ignore!` option/method.
82
+
83
+ ``` ruby
84
+ listener = Listen.to('dir/path/to/listen', ignore: /\.txt/) { |modified, added, removed| # ... }
85
+ listener.start
86
+ listener.ignore! /\.pkg/ # overwrite all patterns and only ignore pkg extension.
87
+ listener.ignore /\.rb/ # ignore rb extension in addition of pkg.
88
+ sleep
89
+ ```
90
+
91
+ Note: `:ignore` regexp patterns are evaluated against relative paths.
92
+
93
+ Note: Ignoring paths does not improve performance, except when Polling ([#274](https://github.com/guard/listen/issues/274))
94
+
95
+ ### Only
96
+
97
+ Listen catches all files (less the ignored ones) by default. If you want to only listen to a specific type of file (i.e., just `.rb` extension), you should use the `only` option/method.
98
+
99
+ ``` ruby
100
+ listener = Listen.to('dir/path/to/listen', only: /\.rb$/) { |modified, added, removed| # ... }
101
+ listener.start
102
+ listener.only /_spec\.rb$/ # overwrite all existing only patterns.
103
+ sleep
104
+ ```
105
+
106
+ Note: `:only` regexp patterns are evaluated only against relative **file** paths.
107
+
108
+
109
+ ## Changes callback
110
+
111
+ Changes to the listened-to directories gets reported back to the user in a callback.
112
+ The registered callback gets invoked, when there are changes, with **three** parameters:
113
+ `modified`, `added` and `removed` paths, in that particular order.
114
+ Paths are always returned in their absolute form.
115
+
116
+ Example:
117
+
118
+ ```ruby
119
+ listener = Listen.to('path/to/app') do |modified, added, removed|
120
+ # This block will be called when there are changes.
121
+ end
122
+ listener.start
123
+ sleep
124
+ ```
125
+
126
+ or ...
127
+
128
+ ```ruby
129
+ # Create a callback
130
+ callback = Proc.new do |modified, added, removed|
131
+ # This proc will be called when there are changes.
132
+ end
133
+ listener = Listen.to('dir', &callback)
134
+ listener.start
135
+ sleep
136
+ ```
137
+
138
+ ## Options
139
+
140
+ All the following options can be set through the `Listen.to` after the directory path(s) params.
141
+
142
+ ```ruby
143
+ ignore: [%r{/foo/bar}, /\.pid$/, /\.coffee$/] # Ignore a list of paths
144
+ # default: See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer
145
+
146
+ ignore!: %r{/foo/bar} # Same as ignore options, but overwrite default ignored paths.
147
+
148
+ only: %r{.rb$} # Only listen to specific files
149
+ # default: none
150
+
151
+ latency: 0.5 # Set the delay (**in seconds**) between checking for changes
152
+ # default: 0.25 sec (1.0 sec for polling)
153
+
154
+ wait_for_delay: 4 # Set the delay (**in seconds**) between calls to the callback when changes exist
155
+ # default: 0.10 sec
156
+
157
+ force_polling: true # Force the use of the polling adapter
158
+ # default: none
159
+
160
+ relative: false # Whether changes should be relative to current dir or not
161
+ # default: false
162
+
163
+ polling_fallback_message: 'custom message' # Set a custom polling fallback message (or disable it with false)
164
+ # default: "Listen will be polling for changes. Learn more at https://github.com/guard/listen#listen-adapters."
165
+ ```
166
+
167
+ ## Debugging
168
+
169
+ Setting the environment variable `LISTEN_GEM_DEBUGGING=1` sets up the INFO level logger, while `LISTEN_GEM_DEBUGGING=2` sets up the DEBUG level logger.
170
+
171
+ You can also set `Listen.logger` to a custom logger.
172
+
173
+
174
+ ## Listen adapters
175
+
176
+ The Listen gem has a set of adapters to notify it when there are changes.
177
+
178
+ There are 4 OS-specific adapters to support Darwin, Linux, \*BSD and Windows.
179
+ These adapters are fast as they use some system-calls to implement the notifying function.
180
+
181
+ There is also a polling adapter - although it's much slower than other adapters,
182
+ it works on every platform/system and scenario (including network filesystems such as VM shared folders).
183
+
184
+ The Darwin and Linux adapters are dependencies of the Listen gem so they work out of the box. For other adapters a specific gem will have to be added to your Gemfile, please read below.
185
+
186
+ The Listen gem will choose the best adapter automatically, if present. If you
187
+ want to force the use of the polling adapter, use the `:force_polling` option
188
+ while initializing the listener.
189
+
190
+ ### On Windows
191
+
192
+ If you are on Windows, it's recommended to use the [`wdm`](https://github.com/Maher4Ever/wdm) adapter instead of polling.
193
+
194
+ Please add the following to your Gemfile:
195
+
196
+ ```ruby
197
+ gem 'wdm', '>= 0.1.0' if Gem.win_platform?
198
+ ```
199
+
200
+ ### On \*BSD
201
+
202
+ If you are on \*BSD you can try to use the [`rb-kqueue`](https://github.com/mat813/rb-kqueue) adapter instead of polling.
203
+
204
+ Please add the following to your Gemfile:
205
+
206
+ ```ruby
207
+ require 'rbconfig'
208
+ if RbConfig::CONFIG['target_os'] =~ /bsd|dragonfly/i
209
+ gem 'rb-kqueue', '>= 0.2'
210
+ end
211
+
212
+ ```
213
+
214
+ ### Getting the [polling fallback message](#options)?
215
+
216
+ Please visit the [installation section of the Listen WIKI](https://github.com/guard/listen/wiki#installation) for more information and options for potential fixes.
217
+
218
+ ### Issues and troubleshooting
219
+
220
+ *NOTE: without providing the output after setting the `LISTEN_GEM_DEBUGGING=1` environment variable, it can be almost impossible to guess why listen is not working as expected.*
221
+
222
+ See [TROUBLESHOOTING](https://github.com/guard/listen/wiki/Troubleshooting)
223
+
224
+ ## Performance
225
+
226
+ If Listen seems slow or unresponsive, make sure you're not using the Polling adapter (you should see a warning upon startup if you are).
227
+
228
+ Also, if the directories you're watching contain many files, make sure you're:
229
+
230
+ * not using Polling (ideally)
231
+ * using `:ignore` and `:only` options to avoid tracking directories you don't care about (important with Polling and on MacOS)
232
+ * running Listen with the `:latency` and `:wait_for_delay` options not too small or too big (depends on needs)
233
+ * not watching directories with log files, database files or other frequently changing files
234
+ * not using a version of Listen prior to 2.7.7
235
+ * not getting silent crashes within Listen (see LISTEN_GEM_DEBUGGING=2)
236
+ * not running multiple instances of Listen in the background
237
+ * using a file system with atime modification disabled (ideally)
238
+ * not using a filesystem with inaccurate file modification times (ideally), e.g. HFS, VFAT
239
+ * not buffering to a slow terminal (e.g. transparency + fancy font + slow gfx card + lots of output)
240
+ * ideally not running a slow encryption stack, e.g. btrfs + ecryptfs
241
+
242
+ When in doubt, LISTEN_GEM_DEBUGGING=2 can help discover the actual events and time they happened.
243
+
244
+ See also [Tips and Techniques](https://github.com/guard/listen/wiki/Tips-and-Techniques).
245
+
246
+ ## Development
247
+
248
+ * Documentation hosted at [RubyDoc](http://rubydoc.info/github/guard/listen/master/frames).
249
+ * Source hosted at [GitHub](https://github.com/guard/listen).
250
+
251
+ Pull requests are very welcome! Please try to follow these simple rules if applicable:
252
+
253
+ * Please create a topic branch for every separate change you make.
254
+ * Make sure your patches are well tested. All specs must pass on [Travis CI](https://travis-ci.org/guard/listen).
255
+ * Update the [Yard](http://yardoc.org/) documentation.
256
+ * Update the [README](https://github.com/guard/listen/blob/master/README.md).
257
+ * Please **do not change** the version number.
258
+
259
+ For questions please join us in our [Google group](http://groups.google.com/group/guard-dev) or on
260
+ `#guard` (irc.freenode.net).
261
+
262
+ ## Acknowledgments
263
+
264
+ * [Michael Kessler (netzpirat)][] for having written the [initial specs](https://github.com/guard/listen/commit/1e457b13b1bb8a25d2240428ce5ed488bafbed1f).
265
+ * [Travis Tilley (ttilley)][] for this awesome work on [fssm][] & [rb-fsevent][].
266
+ * [Nathan Weizenbaum (nex3)][] for [rb-inotify][], a thorough inotify wrapper.
267
+ * [Mathieu Arnold (mat813)][] for [rb-kqueue][], a simple kqueue wrapper.
268
+ * [Maher Sallam][] for [wdm][], windows support wouldn't exist without him.
269
+ * [Yehuda Katz (wycats)][] for [vigilo][], that has been a great source of inspiration.
270
+
271
+ ## Author
272
+
273
+ [Thibaud Guillaume-Gentil](https://github.com/thibaudgg) ([@thibaudgg](https://twitter.com/thibaudgg))
274
+
275
+ ## Contributors
276
+
277
+ [https://github.com/guard/listen/graphs/contributors](https://github.com/guard/listen/graphs/contributors)
278
+
279
+ [Thibaud Guillaume-Gentil (thibaudgg)]: https://github.com/thibaudgg
280
+ [Maher Sallam]: https://github.com/Maher4Ever
281
+ [Michael Kessler (netzpirat)]: https://github.com/netzpirat
282
+ [Travis Tilley (ttilley)]: https://github.com/ttilley
283
+ [fssm]: https://github.com/ttilley/fssm
284
+ [rb-fsevent]: https://github.com/thibaudgg/rb-fsevent
285
+ [Mathieu Arnold (mat813)]: https://github.com/mat813
286
+ [Nathan Weizenbaum (nex3)]: https://github.com/nex3
287
+ [rb-inotify]: https://github.com/nex3/rb-inotify
288
+ [stereobooster]: https://github.com/stereobooster
289
+ [rb-fchange]: https://github.com/stereobooster/rb-fchange
290
+ [rb-kqueue]: https://github.com/mat813/rb-kqueue
291
+ [Yehuda Katz (wycats)]: https://github.com/wycats
292
+ [vigilo]: https://github.com/wycats/vigilo
293
+ [wdm]: https://github.com/Maher4Ever/wdm
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'listen'
4
+ require 'listen/cli'
5
+
6
+ unless defined?(JRUBY_VERSION)
7
+ if Signal.list.keys.include?('INT')
8
+ Signal.trap('INT') { Thread.new { Listen.stop } }
9
+ end
10
+ end
11
+
12
+ Listen::CLI.start
@@ -0,0 +1,61 @@
1
+ require 'logger'
2
+
3
+ module Driskell
4
+ module Listen
5
+ end
6
+ end
7
+
8
+ require 'driskell-listen/logger'
9
+ require 'driskell-listen/listener'
10
+
11
+ require 'driskell-listen/internals/thread_pool'
12
+
13
+ # Always set up logging by default first time file is required
14
+ #
15
+ # NOTE: If you need to clear the logger completely, do so *after*
16
+ # requiring this file. If you need to set a custom logger,
17
+ # require the listen/logger file and set the logger before requiring
18
+ # this file.
19
+ Driskell::Listen.setup_default_logger_if_unset
20
+
21
+ # Won't print anything by default because of level - unless you've set
22
+ # LISTEN_GEM_DEBUGGING or provided your own logger with a high enough level
23
+ Driskell::Listen::Logger.info "Listen loglevel set to: #{Driskell::Listen.logger.level}"
24
+ Driskell::Listen::Logger.info "Listen version: #{Driskell::Listen::VERSION}"
25
+
26
+ module Driskell::Listen
27
+ class << self
28
+ # Listens to file system modifications on a either single directory or
29
+ # multiple directories.
30
+ #
31
+ # @param (see Driskell::Listen::Listener#new)
32
+ #
33
+ # @yield [modified, added, removed] the changed files
34
+ # @yieldparam [Array<String>] modified the list of modified files
35
+ # @yieldparam [Array<String>] added the list of added files
36
+ # @yieldparam [Array<String>] removed the list of removed files
37
+ #
38
+ # @return [Driskell::Listen::Listener] the listener
39
+ #
40
+ def to(*args, &block)
41
+ @listeners ||= []
42
+ Listener.new(*args, &block).tap do |listener|
43
+ @listeners << listener
44
+ end
45
+ end
46
+
47
+ # This is used by the `listen` binary to handle Ctrl-C
48
+ #
49
+ def stop
50
+ Internals::ThreadPool.stop
51
+ @listeners ||= []
52
+
53
+ # TODO: should use a mutex for this
54
+ @listeners.each do |listener|
55
+ # call stop to halt the main loop
56
+ listener.stop
57
+ end
58
+ @listeners = nil
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,44 @@
1
+ require 'driskell-listen/adapter/base'
2
+ require 'driskell-listen/adapter/bsd'
3
+ require 'driskell-listen/adapter/darwin'
4
+ require 'driskell-listen/adapter/linux'
5
+ require 'driskell-listen/adapter/polling'
6
+ require 'driskell-listen/adapter/windows'
7
+ require 'driskell-listen/adapter/simulated_darwin'
8
+
9
+ module Driskell::Listen
10
+ module Adapter
11
+ OPTIMIZED_ADAPTERS = [Darwin, SimulatedDarwin, Linux, BSD, Windows]
12
+ POLLING_FALLBACK_MESSAGE = 'Listen will be polling for changes.'\
13
+ 'Learn more at https://github.com/guard/listen#listen-adapters.'
14
+
15
+ def self.select(options = {})
16
+ _log :debug, 'Adapter: considering polling ...'
17
+ return Polling if options[:force_polling]
18
+ _log :debug, 'Adapter: considering optimized backend...'
19
+ return _usable_adapter_class if _usable_adapter_class
20
+ _log :debug, 'Adapter: falling back to polling...'
21
+ _warn_polling_fallback(options)
22
+ Polling
23
+ rescue
24
+ _log :warn, format('Adapter: failed: %s:%s', $ERROR_POSITION.inspect,
25
+ $ERROR_POSITION * "\n")
26
+ raise
27
+ end
28
+
29
+ private
30
+
31
+ def self._usable_adapter_class
32
+ OPTIMIZED_ADAPTERS.detect(&:usable?)
33
+ end
34
+
35
+ def self._warn_polling_fallback(options)
36
+ msg = options.fetch(:polling_fallback_message, POLLING_FALLBACK_MESSAGE)
37
+ Kernel.warn "[Listen warning]:\n #{msg}" if msg
38
+ end
39
+
40
+ def self._log(type, message)
41
+ Driskell::Listen::Logger.send(type, message)
42
+ end
43
+ end
44
+ end