listen 3.8.0 → 3.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0fcb6d45a23b63f02ec16878ffe9800bc52a32f93fbc5b7e1f03ed647398849
4
- data.tar.gz: 3d05dea88713a500aca3fb2d8612e7a9a9d6125a9c2573f497fe46482386ad84
3
+ metadata.gz: b365e353c2a0dc2a64459faa2c30a9b472130637b5fb4f50977c07adb2c6fd0c
4
+ data.tar.gz: 82d72d4f26f25a7fd1e285fbebe66fffcee246999696313a4f19997ce2017ef5
5
5
  SHA512:
6
- metadata.gz: 81fb2d73327b8d75aff7156f65fc6949d400aef6ef9e6455ee37e0a9d389adb4b010df0565f160001d90da0496887c71bff8f25076c8fa7c37ddb9ce05511fc1
7
- data.tar.gz: 6e1f35517e6557e46e02e3b985792b0a8aa661470117f648d209917a9eac6987282c57fc30ad6857f702305cf695c16081535fc11f8a434974f068c0bb6aeafe
6
+ metadata.gz: f52228164dce447a048dea3e04268909004e17f0b40788495f58f9afc9a9a9f3a0207fd0acb541d0cffe0be78836a10f652acf6ff418cea9ea119708eaec0b83
7
+ data.tar.gz: ee91854777075dc80f4cbcff3e507f4ca162aabe37fa11709b145184ada246efd0401ba89a50de8008c2ca7345d0dd08d20bbad7c6d9272004ad3581e74abca5
data/README.md CHANGED
@@ -14,7 +14,7 @@ The `listen` gem listens to file modifications and notifies you about the change
14
14
  * You can watch multiple directories.
15
15
  * Regexp-patterns for ignoring paths for more accuracy and speed
16
16
  * Increased change detection accuracy on OS X HFS and VFAT volumes.
17
- * Continuous Integration: tested on selected Ruby environments via [Github Workflows](https:///github.com/guard/listen/master/.github/workflows).
17
+ * Continuous Integration: tested on selected Ruby environments via [Github Workflows](https://github.com/guard/listen/tree/master/.github/workflows).
18
18
 
19
19
  ## Issues / limitations
20
20
 
@@ -155,7 +155,7 @@ Note: `:only` regexp patterns are evaluated only against relative **file** paths
155
155
 
156
156
  All the following options can be set through the `Listen.to` after the directory path(s) params.
157
157
 
158
- ```ruby
158
+ ``` ruby
159
159
  ignore: [%r{/foo/bar}, /\.pid$/, /\.coffee$/] # Ignore a list of paths
160
160
  # default: See DEFAULT_IGNORED_FILES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer
161
161
 
@@ -187,7 +187,7 @@ This is the primary method of debugging.
187
187
 
188
188
  ### Custom Logger
189
189
  You can call `Listen.logger =` to set a custom `listen` logger for the process. For example:
190
- ```
190
+ ``` ruby
191
191
  Listen.logger = Rails.logger
192
192
  ```
193
193
 
@@ -197,7 +197,7 @@ If no custom logger is set, a default `listen` logger which logs to to `STDERR`
197
197
  The default logger defaults to the `error` logging level (severity).
198
198
  You can override the logging level by setting the environment variable `LISTEN_GEM_DEBUGGING=<level>`.
199
199
  For `<level>`, all standard `::Logger` levels are supported, with any mix of upper-/lower-case:
200
- ```
200
+ ``` ruby
201
201
  export LISTEN_GEM_DEBUGGING=debug # or 2 [deprecated]
202
202
  export LISTEN_GEM_DEBUGGING=info # or 1 or true or yes [deprecated]
203
203
  export LISTEN_GEM_DEBUGGING=warn
@@ -210,9 +210,38 @@ Note: The alternate values `1`, `2`, `true` and `yes` shown above are deprecated
210
210
 
211
211
  ### Disabling Logging
212
212
  If you want to disable `listen` logging, set
213
- ```
213
+ ``` ruby
214
214
  Listen.logger = ::Logger.new('/dev/null')
215
215
  ```
216
+
217
+ ### Adapter Warnings
218
+ If listen is having trouble with the underlying adapter, it will display warnings with `Kernel#warn` by default,
219
+ which in turn writes to STDERR.
220
+ Sometimes this is not desirable, for example in an environment where STDERR is ignored.
221
+ For these reasons, the behavior can be configured using `Listen.adapter_warn_behavior =`:
222
+ ``` ruby
223
+ Listen.adapter_warn_behavior = :warn # default (true means the same)
224
+ Listen.adapter_warn_behavior = :log # send to logger.warn
225
+ Listen.adapter_warn_behavior = :silent # suppress all adapter warnings (nil or false mean the same)
226
+ ```
227
+ Also there are some cases where specific warnings are not helpful.
228
+ For example, if you are using the polling adapter--and expect to--you can suppress the warning about it
229
+ by providing a callable object like a lambda or proc that determines the behavior based on the `message`:
230
+ ``` ruby
231
+ Listen.adapter_warn_behavior = ->(message) do
232
+ case message
233
+ when /Listen will be polling for changes/
234
+ :silent
235
+ when /directory is already being watched/
236
+ :log
237
+ else
238
+ :warn
239
+ end
240
+ end
241
+ ```
242
+ In cases where the `Listen` gem is embedded inside another service--such as `guard`--the above configuration
243
+ can be set in the environment variable `LISTEN_GEM_ADAPTER_WARN_BEHAVIOR=warn|log|silent`.
244
+
216
245
  ## Listen Adapters
217
246
 
218
247
  The `Listen` gem has a set of adapters to notify it when there are changes.
@@ -34,7 +34,7 @@ module Listen
34
34
  require 'find'
35
35
  true
36
36
  rescue LoadError
37
- Kernel.warn BUNDLER_DECLARE_GEM
37
+ Listen.adapter_warn(BUNDLER_DECLARE_GEM)
38
38
  false
39
39
  end
40
40
 
@@ -30,7 +30,7 @@ module Listen
30
30
  require 'rb-fsevent'
31
31
  fsevent_version = Gem::Version.new(FSEvent::VERSION)
32
32
  return true if fsevent_version <= Gem::Version.new('0.9.4')
33
- Kernel.warn INCOMPATIBLE_GEM_VERSION
33
+ Listen.adapter_warn(INCOMPATIBLE_GEM_VERSION)
34
34
  false
35
35
  end
36
36
 
@@ -20,7 +20,7 @@ module Listen
20
20
  Listen.logger.debug format('wdm - load failed: %s:%s', $ERROR_INFO,
21
21
  $ERROR_POSITION * "\n")
22
22
 
23
- Kernel.warn BUNDLER_DECLARE_GEM
23
+ Listen.adapter_warn(BUNDLER_DECLARE_GEM)
24
24
  false
25
25
  end
26
26
 
@@ -36,7 +36,7 @@ module Listen
36
36
 
37
37
  def _warn_polling_fallback(options)
38
38
  msg = options.fetch(:polling_fallback_message, POLLING_FALLBACK_MESSAGE)
39
- Kernel.warn "[Listen warning]:\n #{msg}" if msg
39
+ Listen.adapter_warn("[Listen warning]:\n #{msg}") if msg
40
40
  end
41
41
  end
42
42
  end
data/lib/listen/logger.rb CHANGED
@@ -6,13 +6,27 @@ module Listen
6
6
  # Listen.logger will always be present.
7
7
  # If you don't want logging, set Listen.logger = ::Logger.new('/dev/null', level: ::Logger::UNKNOWN)
8
8
 
9
+ @adapter_warn_behavior = :warn
10
+
9
11
  class << self
10
12
  attr_writer :logger
13
+ attr_accessor :adapter_warn_behavior
11
14
 
12
15
  def logger
13
16
  @logger ||= default_logger
14
17
  end
15
18
 
19
+ def adapter_warn(message)
20
+ case ENV['LISTEN_GEM_ADAPTER_WARN_BEHAVIOR']&.to_sym || adapter_warn_behavior_callback(message)
21
+ when :log
22
+ logger.warn(message)
23
+ when :silent, nil, false
24
+ # do nothing
25
+ else # :warn
26
+ warn(message)
27
+ end
28
+ end
29
+
16
30
  private
17
31
 
18
32
  def default_logger
@@ -32,5 +46,20 @@ module Listen
32
46
 
33
47
  ::Logger.new(STDERR, level: level)
34
48
  end
49
+
50
+ def adapter_warn_behavior_callback(message)
51
+ if adapter_warn_behavior.respond_to?(:call)
52
+ case behavior = adapter_warn_behavior.call(message)
53
+ when Symbol
54
+ behavior
55
+ when false, nil
56
+ :silent
57
+ else
58
+ :warn
59
+ end
60
+ else
61
+ adapter_warn_behavior
62
+ end
63
+ end
35
64
  end
36
65
  end
@@ -30,6 +30,12 @@ module Listen
30
30
  @real_dirs.add?(real_path) or _fail(entry.sys_path, real_path)
31
31
  end
32
32
 
33
+ # Leaving this stub here since some warning work-arounds were referring to it.
34
+ # Deprecated. Will be removed in Listen v4.0.
35
+ def warn(message)
36
+ Listen.adapter_warn(message)
37
+ end
38
+
33
39
  private
34
40
 
35
41
  def _fail(symlinked, real_path)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Listen
4
- VERSION = '3.8.0'
4
+ VERSION = '3.9.0'
5
5
  end
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.8.0
4
+ version: 3.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibaud Guillaume-Gentil
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-09 00:00:00.000000000 Z
11
+ date: 2024-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb-fsevent
@@ -103,10 +103,10 @@ metadata:
103
103
  allowed_push_host: https://rubygems.org
104
104
  bug_tracker_uri: https://github.com/guard/listen/issues
105
105
  changelog_uri: https://github.com/guard/listen/releases
106
- documentation_uri: https://www.rubydoc.info/gems/listen/3.8.0
106
+ documentation_uri: https://www.rubydoc.info/gems/listen/3.9.0
107
107
  homepage_uri: https://github.com/guard/listen
108
- source_code_uri: https://github.com/guard/listen/tree/v3.8.0
109
- post_install_message:
108
+ source_code_uri: https://github.com/guard/listen/tree/v3.9.0
109
+ post_install_message:
110
110
  rdoc_options: []
111
111
  require_paths:
112
112
  - lib
@@ -121,8 +121,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  - !ruby/object:Gem::Version
122
122
  version: '0'
123
123
  requirements: []
124
- rubygems_version: 3.0.1
125
- signing_key:
124
+ rubygems_version: 3.4.6
125
+ signing_key:
126
126
  specification_version: 4
127
127
  summary: Listen to file modifications
128
128
  test_files: []