Skip to content

Commit 8f38056

Browse files
authored
Monkey Patch Listen SymlinkDetector warning (#182)
* Monkey Patch Listen::Record::SymlinkDetector#_fail This removes the warning made from Ruby while still keeping it available with the Listen.logger on :warn level You can enable symlink warnings with `LISTEN_GEM_DEBUGGING=warn` when using retest * Silence Ruby warnings when monkey patching Listen module
1 parent bcea704 commit 8f38056

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ GEM
1010
remote: https://rubygems.org/
1111
specs:
1212
byebug (11.1.3)
13-
ffi (1.15.5)
13+
ffi (1.16.3)
1414
listen (3.8.0)
1515
rb-fsevent (~> 0.10, >= 0.10.3)
1616
rb-inotify (~> 0.9, >= 0.9.10)

lib/config/listen.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# lib/config/listen.rb:4: warning: method redefined; discarding old _fail
2+
# ~/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/listen-3.8.0/lib/listen/record/symlink_detector.rb:35: warning: previous definition of _fail was here
3+
4+
# Runs a block of code without warnings.
5+
def silence_warnings(&block)
6+
warn_level = $VERBOSE
7+
$VERBOSE = nil
8+
result = block.call
9+
$VERBOSE = warn_level
10+
result
11+
end
12+
13+
silence_warnings do
14+
15+
# TODO: Update monkey patch when decision is made about
16+
# https://github.com/guard/listen/issues/572
17+
18+
module Listen
19+
class Record
20+
class SymlinkDetector
21+
def _fail(symlinked, real_path)
22+
Listen.logger.warn(format(SYMLINK_LOOP_ERROR, symlinked, real_path))
23+
raise Error, "Don't watch locally-symlinked directory twice"
24+
end
25+
end
26+
end
27+
end
28+
29+
end

lib/retest.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
require 'listen'
2+
require 'config/listen'
3+
24
require 'string/similarity'
35
require 'observer'
46

0 commit comments

Comments
 (0)