listen 3.3.0.pre.2 → 3.3.0.pre.3
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.
- checksums.yaml +4 -4
- data/README.md +104 -60
- data/lib/listen/adapter/linux.rb +1 -0
- data/lib/listen/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d6639e347ad2eafe447bbb0c00b50ceab5e3f7a6b3bdce169482c910765198d
|
4
|
+
data.tar.gz: 617efbcc3815ea658bc886e02d9ee24a0dd142cc0273442d4323d55766c5d8ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e55c50925feb8a8909978344e3061cec23ae2ee9cdba2583928da45bb907eb17284e7fb94aad431c9b1ba141f6401f98f131c6b774fe49619ea7bf353c6f352
|
7
|
+
data.tar.gz: 221ca770caf975a3bd686704e93888a852cba10e725f582c22076a42d0540b085f929faaf474b9d81690beb0c88fb647107e3bf296e738bd913d1c0f5097a442
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Listen
|
2
2
|
|
3
|
-
The
|
3
|
+
The `listen` gem listens to file modifications and notifies you about the changes.
|
4
4
|
|
5
|
-
: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.
|
5
|
+
: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.
|
6
6
|
|
7
7
|
[](https://github.com/guard/listen/actions?workflow=Development)
|
8
8
|
[](http://badge.fury.io/rb/listen)
|
@@ -25,37 +25,81 @@ The Listen gem listens to file modifications and notifies you about the changes.
|
|
25
25
|
* 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)).
|
26
26
|
* No directory/adapter-specific configuration options.
|
27
27
|
* Support for plugins planned for future.
|
28
|
-
* TCP functionality was removed in
|
28
|
+
* 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'`.
|
29
29
|
* Some filesystems won't work without polling (VM/Vagrant Shared folders, NFS, Samba, sshfs, etc.).
|
30
30
|
* Specs suite on JRuby and Rubinius aren't reliable on Travis CI, but should work.
|
31
31
|
* Windows and \*BSD adapter aren't continuously and automatically tested.
|
32
32
|
* OSX adapter has some performance limitations ([#342](https://github.com/guard/listen/issues/342)).
|
33
|
-
*
|
33
|
+
* FreeBSD users need patched version of rb-kqueue (as of 2020/11). See #475 for the issue, mat813/rb-kqueue#12 for the patch, and Bug 250432 in bugzilla.
|
34
34
|
* Listeners do not notify across forked processes, if you wish for multiple processes to receive change notifications you must [listen inside of each process](https://github.com/guard/listen/issues/398#issuecomment-223957952).
|
35
35
|
|
36
36
|
Pull requests or help is very welcome for these.
|
37
37
|
|
38
38
|
## Install
|
39
39
|
|
40
|
-
The simplest way to install
|
40
|
+
The simplest way to install `listen` is to use [Bundler](http://bundler.io).
|
41
41
|
|
42
42
|
```ruby
|
43
|
-
gem 'listen', '~> 3.
|
43
|
+
gem 'listen', '~> 3.3' # NOTE: for TCP functionality, use '~> 2.10' for now
|
44
|
+
```
|
45
|
+
|
46
|
+
## Complete Example
|
47
|
+
Here is a complete example of using the `listen` gem:
|
48
|
+
```ruby
|
49
|
+
require 'listen'
|
50
|
+
|
51
|
+
listener = Listen.to('/srv/app') do |modified, added, removed|
|
52
|
+
puts(modified: modified, added: added, removed: removed)
|
53
|
+
end
|
54
|
+
listener.start
|
55
|
+
sleep
|
56
|
+
```
|
57
|
+
Running the above in the background, you can see the callback block being called in response to each command:
|
58
|
+
```
|
59
|
+
$ cd /srv/app
|
60
|
+
$ touch a.txt
|
61
|
+
{:modified=>[], :added=>["/srv/app/a.txt"], :removed=>[]}
|
62
|
+
|
63
|
+
$ echo more >> a.txt
|
64
|
+
{:modified=>["/srv/app/a.txt"], :added=>[], :removed=>[]}
|
65
|
+
|
66
|
+
$ mv a.txt b.txt
|
67
|
+
{:modified=>[], :added=>["/srv/app/b.txt"], :removed=>["/srv/app/a.txt"]}
|
68
|
+
|
69
|
+
$ vi b.txt
|
70
|
+
# add a line to this new file and press ZZ to save and exit
|
71
|
+
{:modified=>["/srv/app/b.txt"], :added=>[], :removed=>[]}
|
72
|
+
|
73
|
+
$ vi c.txt
|
74
|
+
# add a line and press ZZ to save and exit
|
75
|
+
{:modified=>[], :added=>["/srv/app/c.txt"], :removed=>[]}
|
76
|
+
|
77
|
+
$ rm b.txt c.txt
|
78
|
+
{:modified=>[], :added=>[], :removed=>["/srv/app/b.txt", "/srv/app/c.txt"]}
|
44
79
|
```
|
45
80
|
|
46
81
|
## Usage
|
47
82
|
|
48
|
-
Call `Listen.to` with
|
83
|
+
Call `Listen.to` with one or more directories and the "changes" callback passed as a block.
|
49
84
|
|
50
85
|
``` ruby
|
51
86
|
listener = Listen.to('dir/to/listen', 'dir/to/listen2') do |modified, added, removed|
|
52
|
-
puts "modified absolute path: #{modified}"
|
53
|
-
puts "added absolute path: #{added}"
|
54
|
-
puts "removed absolute path: #{removed}"
|
87
|
+
puts "modified absolute path array: #{modified}"
|
88
|
+
puts "added absolute path array: #{added}"
|
89
|
+
puts "removed absolute path array: #{removed}"
|
55
90
|
end
|
56
|
-
listener.start # not
|
91
|
+
listener.start # starts a listener thread--does not block
|
92
|
+
|
93
|
+
# do whatever you want here...just don't exit the process :)
|
94
|
+
|
57
95
|
sleep
|
58
96
|
```
|
97
|
+
## Changes Callback
|
98
|
+
|
99
|
+
Changes to the listened-to directories are reported by the listener thread in a callback.
|
100
|
+
The callback receives **three** array parameters: `modified`, `added` and `removed`, in that order.
|
101
|
+
Each of these three is always an array with 0 or more entries.
|
102
|
+
Each array entry is an absolute path.
|
59
103
|
|
60
104
|
### Pause / unpause / stop
|
61
105
|
|
@@ -76,13 +120,14 @@ listener.unpause # resumes processing changes ("start" would do the same)
|
|
76
120
|
listener.stop # stop both listening to changes and processing them
|
77
121
|
```
|
78
122
|
|
79
|
-
Note: While paused,
|
123
|
+
Note: While paused, `listen` keeps on collecting changes in the background - to clear them, call `stop`.
|
80
124
|
|
81
|
-
Note: You should keep track of all started listeners and stop them properly on finish.
|
125
|
+
Note: You should keep track of all started listeners and `stop` them properly on finish.
|
82
126
|
|
83
127
|
### Ignore / ignore!
|
84
128
|
|
85
|
-
Listen ignores some directories and extensions by default (See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer)
|
129
|
+
`Listen` ignores some directories and extensions by default (See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer).
|
130
|
+
You can add ignoring patterns with the `ignore` option/method or overwrite default with `ignore!` option/method.
|
86
131
|
|
87
132
|
``` ruby
|
88
133
|
listener = Listen.to('dir/path/to/listen', ignore: /\.txt/) { |modified, added, removed| # ... }
|
@@ -94,11 +139,11 @@ sleep
|
|
94
139
|
|
95
140
|
Note: `:ignore` regexp patterns are evaluated against relative paths.
|
96
141
|
|
97
|
-
Note: Ignoring paths does not improve performance, except when Polling ([#274](https://github.com/guard/listen/issues/274))
|
142
|
+
Note: Ignoring paths does not improve performance, except when Polling ([#274](https://github.com/guard/listen/issues/274)).
|
98
143
|
|
99
144
|
### Only
|
100
145
|
|
101
|
-
Listen
|
146
|
+
`Listen` watches 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.
|
102
147
|
|
103
148
|
``` ruby
|
104
149
|
listener = Listen.to('dir/path/to/listen', only: /\.rb$/) { |modified, added, removed| # ... }
|
@@ -110,35 +155,6 @@ sleep
|
|
110
155
|
Note: `:only` regexp patterns are evaluated only against relative **file** paths.
|
111
156
|
|
112
157
|
|
113
|
-
## Changes callback
|
114
|
-
|
115
|
-
Changes to the listened-to directories gets reported back to the user in a callback.
|
116
|
-
The registered callback gets invoked, when there are changes, with **three** parameters:
|
117
|
-
`modified`, `added` and `removed` paths, in that particular order.
|
118
|
-
Paths are always returned in their absolute form.
|
119
|
-
|
120
|
-
Example:
|
121
|
-
|
122
|
-
```ruby
|
123
|
-
listener = Listen.to('path/to/app') do |modified, added, removed|
|
124
|
-
# This block will be called when there are changes.
|
125
|
-
end
|
126
|
-
listener.start
|
127
|
-
sleep
|
128
|
-
```
|
129
|
-
|
130
|
-
or ...
|
131
|
-
|
132
|
-
```ruby
|
133
|
-
# Create a callback
|
134
|
-
callback = Proc.new do |modified, added, removed|
|
135
|
-
# This proc will be called when there are changes.
|
136
|
-
end
|
137
|
-
listener = Listen.to('dir', &callback)
|
138
|
-
listener.start
|
139
|
-
sleep
|
140
|
-
```
|
141
|
-
|
142
158
|
## Options
|
143
159
|
|
144
160
|
All the following options can be set through the `Listen.to` after the directory path(s) params.
|
@@ -168,16 +184,42 @@ polling_fallback_message: 'custom message' # Set a custom polling fallback
|
|
168
184
|
# default: "Listen will be polling for changes. Learn more at https://github.com/guard/listen#listen-adapters."
|
169
185
|
```
|
170
186
|
|
171
|
-
## Debugging
|
187
|
+
## Logging and Debugging
|
188
|
+
|
189
|
+
`Listen` logs its activity to `Listen.logger`.
|
190
|
+
This is the primary method of debugging.
|
191
|
+
|
192
|
+
### Custom Logger
|
193
|
+
You can call `Listen.logger =` to set a custom `listen` logger for the process. For example:
|
194
|
+
```
|
195
|
+
Listen.logger = Rails.logger
|
196
|
+
```
|
172
197
|
|
173
|
-
|
198
|
+
### Default Logger
|
199
|
+
If no custom logger is set, a default `listen` logger which logs to to `STDERR` will be created and assigned to `Listen.logger`.
|
174
200
|
|
175
|
-
|
201
|
+
The default logger defaults to the `error` logging level (severity).
|
202
|
+
You can override the logging level by setting the environment variable `LISTEN_GEM_DEBUGGING=<level>`.
|
203
|
+
For `<level>`, all standard `::Logger` levels are supported, with any mix of upper-/lower-case:
|
204
|
+
```
|
205
|
+
export LISTEN_GEM_DEBUGGING=debug # or 2 [deprecated]
|
206
|
+
export LISTEN_GEM_DEBUGGING=info # or 1 or true or yes [deprecated]
|
207
|
+
export LISTEN_GEM_DEBUGGING=warn
|
208
|
+
export LISTEN_GEM_DEBUGGING=fatal
|
209
|
+
export LISTEN_GEM_DEBUGGING=error
|
210
|
+
```
|
211
|
+
The default of `error` will be used if an unsupported value is set.
|
176
212
|
|
213
|
+
Note: The alternate values `1`, `2`, `true` and `yes` shown above are deprecated and will be removed from `listen` v4.0.
|
177
214
|
|
178
|
-
|
215
|
+
### Disabling Logging
|
216
|
+
If you want to disable `listen` logging, set
|
217
|
+
```
|
218
|
+
Listen.logger = ::Logger.new('/dev/null')
|
219
|
+
```
|
220
|
+
## Listen Adapters
|
179
221
|
|
180
|
-
The Listen gem has a set of adapters to notify it when there are changes.
|
222
|
+
The `Listen` gem has a set of adapters to notify it when there are changes.
|
181
223
|
|
182
224
|
There are 4 OS-specific adapters to support Darwin, Linux, \*BSD and Windows.
|
183
225
|
These adapters are fast as they use some system-calls to implement the notifying function.
|
@@ -185,9 +227,9 @@ These adapters are fast as they use some system-calls to implement the notifying
|
|
185
227
|
There is also a polling adapter - although it's much slower than other adapters,
|
186
228
|
it works on every platform/system and scenario (including network filesystems such as VM shared folders).
|
187
229
|
|
188
|
-
The Darwin and Linux adapters are dependencies of the
|
230
|
+
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.
|
189
231
|
|
190
|
-
The
|
232
|
+
The `listen` gem will choose the best adapter automatically, if present. If you
|
191
233
|
want to force the use of the polling adapter, use the `:force_polling` option
|
192
234
|
while initializing the listener.
|
193
235
|
|
@@ -219,31 +261,33 @@ end
|
|
219
261
|
|
220
262
|
Please visit the [installation section of the Listen WIKI](https://github.com/guard/listen/wiki#installation) for more information and options for potential fixes.
|
221
263
|
|
222
|
-
### Issues and
|
264
|
+
### Issues and Troubleshooting
|
265
|
+
|
266
|
+
If the gem doesn't work as expected, start by setting `LISTEN_GEM_DEBUGGING=debug` or `LISTEN_GEM_DEBUGGING=info` as described above in [Logging and Debugging](#logging-and-debugging).
|
223
267
|
|
224
|
-
*NOTE: without providing the output after setting the `LISTEN_GEM_DEBUGGING=
|
268
|
+
*NOTE: without providing the output after setting the `LISTEN_GEM_DEBUGGING=debug` environment variable, it is usually impossible to guess why `listen` is not working as expected.*
|
225
269
|
|
226
270
|
See [TROUBLESHOOTING](https://github.com/guard/listen/wiki/Troubleshooting)
|
227
271
|
|
228
272
|
## Performance
|
229
273
|
|
230
|
-
If
|
274
|
+
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).
|
231
275
|
|
232
276
|
Also, if the directories you're watching contain many files, make sure you're:
|
233
277
|
|
234
278
|
* not using Polling (ideally)
|
235
279
|
* using `:ignore` and `:only` options to avoid tracking directories you don't care about (important with Polling and on MacOS)
|
236
|
-
* running
|
280
|
+
* running `listen` with the `:latency` and `:wait_for_delay` options not too small or too big (depends on needs)
|
237
281
|
* not watching directories with log files, database files or other frequently changing files
|
238
|
-
* not using a version of
|
239
|
-
* not getting silent crashes within
|
240
|
-
* not running multiple instances of
|
282
|
+
* not using a version of `listen` prior to 2.7.7
|
283
|
+
* not getting silent crashes within `listen` (see `LISTEN_GEM_DEBUGGING=debug`)
|
284
|
+
* not running multiple instances of `listen` in the background
|
241
285
|
* using a file system with atime modification disabled (ideally)
|
242
286
|
* not using a filesystem with inaccurate file modification times (ideally), e.g. HFS, VFAT
|
243
287
|
* not buffering to a slow terminal (e.g. transparency + fancy font + slow gfx card + lots of output)
|
244
288
|
* ideally not running a slow encryption stack, e.g. btrfs + ecryptfs
|
245
289
|
|
246
|
-
When in doubt, LISTEN_GEM_DEBUGGING=
|
290
|
+
When in doubt, `LISTEN_GEM_DEBUGGING=debug` can help discover the actual events and time they happened.
|
247
291
|
|
248
292
|
See also [Tips and Techniques](https://github.com/guard/listen/wiki/Tips-and-Techniques).
|
249
293
|
|
data/lib/listen/adapter/linux.rb
CHANGED
data/lib/listen/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: listen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.0.pre.
|
4
|
+
version: 3.3.0.pre.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thibaud Guillaume-Gentil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rb-fsevent
|