listen 3.8.0 → 3.10.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0fcb6d45a23b63f02ec16878ffe9800bc52a32f93fbc5b7e1f03ed647398849
4
- data.tar.gz: 3d05dea88713a500aca3fb2d8612e7a9a9d6125a9c2573f497fe46482386ad84
3
+ metadata.gz: 1e8eccc119beebe2f5153f7fdba4cd313d48c5c7e6334fa3dff5a44bcfbbb720
4
+ data.tar.gz: be423bbdfe20ba4908fc97f9f0ac78bf26060c23e40ed5adf8c07925174245f4
5
5
  SHA512:
6
- metadata.gz: 81fb2d73327b8d75aff7156f65fc6949d400aef6ef9e6455ee37e0a9d389adb4b010df0565f160001d90da0496887c71bff8f25076c8fa7c37ddb9ce05511fc1
7
- data.tar.gz: 6e1f35517e6557e46e02e3b985792b0a8aa661470117f648d209917a9eac6987282c57fc30ad6857f702305cf695c16081535fc11f8a434974f068c0bb6aeafe
6
+ metadata.gz: 596b34d1eeb1d98519303cc0eaced3b4ba87e28b0311a1b96626519c9afd66d90a29b9cc95444d18cf2e42247ed99f9eda86a4d0fa09e19348b60f0f3f63af59
7
+ data.tar.gz: 6c89b5bddcc73b889d58dc7364f8ed2f7d0c395eb9125215fb890bdd2a11fca9fad3bffc6da47cd83a43453169b40f1a94057c8dd818ea6c448863e594ae98c4
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.
@@ -236,7 +265,7 @@ If you are on Windows, it's recommended to use the [`wdm`](https://github.com/Ma
236
265
  Please add the following to your Gemfile:
237
266
 
238
267
  ```ruby
239
- gem 'wdm', '>= 0.1.0', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
268
+ gem 'wdm', '>= 0.1.0'
240
269
  ```
241
270
 
242
271
  ### On \*BSD
@@ -246,11 +275,7 @@ If you are on \*BSD you can try to use the [`rb-kqueue`](https://github.com/mat8
246
275
  Please add the following to your Gemfile:
247
276
 
248
277
  ```ruby
249
- require 'rbconfig'
250
- if RbConfig::CONFIG['target_os'] =~ /bsd|dragonfly/i
251
- gem 'rb-kqueue', '>= 0.2'
252
- end
253
-
278
+ gem 'rb-kqueue', '>= 0.2'
254
279
  ```
255
280
 
256
281
  ### Getting the [polling fallback message](#options)?
@@ -328,6 +353,9 @@ $ sudo sysctl -p
328
353
  ```
329
354
  You may also need to pay attention to the values of `max_queued_events` and `max_user_instances` if Listen keeps on complaining.
330
355
 
356
+ While 524,288 is the maximum number of files that can be watched. Each file watch [takes up 1,080 bytes](https://stackoverflow.com/a/7091897/1156119) on a 64-bit system, so assuming that all 524,288 watches are consumed, that allocates around 540 MiB.
357
+ If you're in an environment that is particularly memory-constrained, consider to specify a lower number.
358
+
331
359
  #### More info
332
360
  Man page for [inotify(7)](https://linux.die.net/man/7/inotify).
333
361
  Blog post: [limit of inotify](https://blog.sorah.jp/2012/01/24/inotify-limitation).
@@ -402,7 +430,7 @@ When in doubt, `LISTEN_GEM_DEBUGGING=debug` can help discover the actual events
402
430
  Pull requests are very welcome! Please try to follow these simple rules if applicable:
403
431
 
404
432
  * Please create a topic branch for every separate change you make.
405
- * Make sure your patches are well tested. All specs must pass on [Travis CI](https://travis-ci.org/guard/listen).
433
+ * Make sure your patches are well tested. All specs must pass on [CI](https://github.com/guard/listen/actions?workflow=Development).
406
434
  * Update the [Yard](http://yardoc.org/) documentation.
407
435
  * Update the [README](https://github.com/guard/listen/blob/master/README.md).
408
436
  * Please **do not change** the version number.
@@ -7,7 +7,7 @@
7
7
  module Listen
8
8
  module Adapter
9
9
  class BSD < Base
10
- OS_REGEXP = /bsd|dragonfly/i.freeze
10
+ OS_REGEXP = /bsd|dragonfly/i
11
11
 
12
12
  DEFAULTS = {
13
13
  events: [
@@ -22,10 +22,7 @@ module Listen
22
22
 
23
23
  BUNDLER_DECLARE_GEM = <<-EOS.gsub(/^ {6}/, '')
24
24
  Please add the following to your Gemfile to avoid polling for changes:
25
- require 'rbconfig'
26
- if RbConfig::CONFIG['target_os'] =~ /#{OS_REGEXP}/
27
- gem 'rb-kqueue', '>= 0.2'
28
- end
25
+ gem 'rb-kqueue', '>= 0.2'
29
26
  EOS
30
27
 
31
28
  def self.usable?
@@ -34,7 +31,7 @@ module Listen
34
31
  require 'find'
35
32
  true
36
33
  rescue LoadError
37
- Kernel.warn BUNDLER_DECLARE_GEM
34
+ Listen.adapter_warn(BUNDLER_DECLARE_GEM)
38
35
  false
39
36
  end
40
37
 
@@ -7,7 +7,7 @@ module Listen
7
7
  # Adapter implementation for Mac OS X `FSEvents`.
8
8
  #
9
9
  class Darwin < Base
10
- OS_REGEXP = /darwin(?<major_version>(1|2)\d+)/i.freeze
10
+ OS_REGEXP = /darwin(?<major_version>(1|2)\d+)/i
11
11
 
12
12
  # The default delay between checking for changes.
13
13
  DEFAULTS = { latency: 0.1 }.freeze
@@ -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
 
@@ -4,7 +4,7 @@ module Listen
4
4
  module Adapter
5
5
  # @see https://github.com/nex3/rb-inotify
6
6
  class Linux < Base
7
- OS_REGEXP = /linux/i.freeze
7
+ OS_REGEXP = /linux/i
8
8
 
9
9
  DEFAULTS = {
10
10
  events: [
@@ -60,7 +60,7 @@ module Listen
60
60
 
61
61
  cookie_params = event.cookie.zero? ? {} : { cookie: event.cookie }
62
62
 
63
- # Note: don't pass options to force rescanning the directory, so we can
63
+ # NOTE: don't pass options to force rescanning the directory, so we can
64
64
  # detect moving/deleting a whole tree
65
65
  if _dir_event?(event)
66
66
  _queue_change(:dir, dir, rel_path, cookie_params)
@@ -8,7 +8,7 @@ module Listen
8
8
  # file IO than the other implementations.
9
9
  #
10
10
  class Polling < Base
11
- OS_REGEXP = //.freeze # match every OS
11
+ OS_REGEXP = // # match every OS
12
12
 
13
13
  DEFAULTS = { latency: 1.0, wait_for_delay: 0.05 }.freeze
14
14
 
@@ -5,11 +5,11 @@ module Listen
5
5
  # Adapter implementation for Windows `wdm`.
6
6
  #
7
7
  class Windows < Base
8
- OS_REGEXP = /mswin|mingw|cygwin/i.freeze
8
+ OS_REGEXP = /mswin|mingw|cygwin/i
9
9
 
10
10
  BUNDLER_DECLARE_GEM = <<-EOS.gsub(/^ {6}/, '')
11
11
  Please add the following to your Gemfile to avoid polling for changes:
12
- gem 'wdm', '>= 0.1.0' if Gem.win_platform?
12
+ gem 'wdm', '>= 0.1.0'
13
13
  EOS
14
14
 
15
15
  def self.usable?
@@ -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
@@ -12,7 +12,6 @@ module Listen
12
12
  wait_for_delay,
13
13
  &block
14
14
  )
15
-
16
15
  @listener = listener
17
16
  @event_queue = event_queue
18
17
  @queue_optimizer = queue_optimizer
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'thread'
4
-
5
3
  require 'timeout'
6
4
  require 'listen/event/processor'
7
5
  require 'listen/thread'
@@ -85,11 +85,13 @@ module Listen
85
85
 
86
86
  # blocks until event is popped
87
87
  # returns the event or `nil` when the event_queue is closed
88
+ # rubocop:disable Naming/MemoizedInstanceVariableName
88
89
  def _wait_until_events
89
90
  config.event_queue.pop.tap do |_event|
90
91
  @_remember_time_of_first_unprocessed_event ||= MonotonicTime.now
91
92
  end
92
93
  end
94
+ # rubocop:enable Naming/MemoizedInstanceVariableName
93
95
 
94
96
  def _flush_wakeup_reasons
95
97
  until @reasons.empty?
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'thread'
4
-
5
3
  require 'forwardable'
6
4
 
7
5
  module Listen
data/lib/listen/fsm.rb CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  # Code copied from https://github.com/celluloid/celluloid-fsm
4
4
 
5
- require 'thread'
6
-
7
5
  module Listen
8
6
  module FSM
9
7
  # Included hook to extend class methods
@@ -38,7 +36,7 @@ module Listen
38
36
  end
39
37
  end
40
38
 
41
- # Note: including classes must call initialize_fsm from their initialize method.
39
+ # NOTE: including classes must call initialize_fsm from their initialize method.
42
40
  def initialize_fsm
43
41
  @fsm_initialized = true
44
42
  @state = self.class.start_state
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
@@ -12,7 +12,6 @@ module Listen
12
12
  given_options.empty? or raise ArgumentError, "Unknown options: #{given_options.inspect}"
13
13
  end
14
14
 
15
- # rubocop:disable Lint/MissingSuper
16
15
  def respond_to_missing?(name, *_)
17
16
  @options.has_key?(name)
18
17
  end
@@ -21,6 +20,5 @@ module Listen
21
20
  respond_to_missing?(name) or raise NameError, "Bad option: #{name.inspect} (valid:#{@options.keys.inspect})"
22
21
  @options[name]
23
22
  end
24
- # rubocop:enable Lint/MissingSuper
25
23
  end
26
24
  end
@@ -9,7 +9,7 @@ module Listen
9
9
  class SymlinkDetector
10
10
  README_URL = 'https://github.com/guard/listen/blob/master/README.md'
11
11
 
12
- SYMLINK_LOOP_ERROR = <<-EOS
12
+ SYMLINK_LOOP_ERROR = <<-EOS.freeze
13
13
  ** ERROR: directory is already being watched! **
14
14
 
15
15
  Directory: %s
@@ -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)
data/lib/listen/record.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'thread'
4
3
  require 'listen/record/entry'
5
4
  require 'listen/record/symlink_detector'
6
5
 
@@ -73,7 +72,7 @@ module Listen
73
72
  private
74
73
 
75
74
  def empty_dirname?(dirname)
76
- dirname == '.' || dirname == ''
75
+ ['.', ''].include?(dirname)
77
76
  end
78
77
 
79
78
  def reset_tree
@@ -18,7 +18,7 @@ module Listen
18
18
  # emacs temp files
19
19
  | \#.+\#
20
20
  | \.\#.+
21
- )(/|\z)}x.freeze
21
+ )(/|\z)}x
22
22
 
23
23
  # The default list of files that get ignored.
24
24
  DEFAULT_IGNORED_EXTENSIONS = %r{(?:
@@ -59,7 +59,7 @@ module Listen
59
59
  | \.DS_Store
60
60
  | \.tmp
61
61
  | ~
62
- )\z}x.freeze
62
+ )\z}x
63
63
 
64
64
  # TODO: deprecate these mutators; use attr_reader instead
65
65
  attr_accessor :only_patterns, :ignore_patterns
@@ -75,7 +75,7 @@ module Listen
75
75
  end
76
76
 
77
77
  def silenced?(relative_path, type)
78
- path = relative_path.to_s # in case it is a Pathname
78
+ path = relative_path.to_s # in case it is a Pathname
79
79
 
80
80
  _ignore?(path) || (only_patterns && type == :file && !_only?(path))
81
81
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Listen
4
- VERSION = '3.8.0'
4
+ VERSION = '3.10.0'
5
5
  end
metadata CHANGED
@@ -1,15 +1,29 @@
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.10.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: 2026-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rb-fsevent
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -103,10 +117,10 @@ metadata:
103
117
  allowed_push_host: https://rubygems.org
104
118
  bug_tracker_uri: https://github.com/guard/listen/issues
105
119
  changelog_uri: https://github.com/guard/listen/releases
106
- documentation_uri: https://www.rubydoc.info/gems/listen/3.8.0
120
+ documentation_uri: https://www.rubydoc.info/gems/listen/3.10.0
107
121
  homepage_uri: https://github.com/guard/listen
108
- source_code_uri: https://github.com/guard/listen/tree/v3.8.0
109
- post_install_message:
122
+ source_code_uri: https://github.com/guard/listen/tree/v3.10.0
123
+ post_install_message:
110
124
  rdoc_options: []
111
125
  require_paths:
112
126
  - lib
@@ -121,8 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
135
  - !ruby/object:Gem::Version
122
136
  version: '0'
123
137
  requirements: []
124
- rubygems_version: 3.0.1
125
- signing_key:
138
+ rubygems_version: 3.4.19
139
+ signing_key:
126
140
  specification_version: 4
127
141
  summary: Listen to file modifications
128
142
  test_files: []