listen 3.2.1 → 3.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Listen
2
4
  class Silencer
3
5
  # The default list of directories that get ignored.
@@ -12,7 +14,7 @@ module Listen
12
14
  | log
13
15
  | tmp
14
16
  |vendor/ruby
15
- )(/|$)}x
17
+ )(/|$)}x.freeze
16
18
 
17
19
  # The default list of files that get ignored.
18
20
  DEFAULT_IGNORED_EXTENSIONS = %r{(?:
@@ -53,7 +55,7 @@ module Listen
53
55
  | \.DS_Store
54
56
  | \.tmp
55
57
  | ~
56
- )$}x
58
+ )$}x.freeze
57
59
 
58
60
  attr_accessor :only_patterns, :ignore_patterns
59
61
 
@@ -73,16 +75,18 @@ module Listen
73
75
  def silenced?(relative_path, type)
74
76
  path = relative_path.to_s
75
77
 
76
- if only_patterns && type == :file
77
- return true unless only_patterns.any? { |pattern| path =~ pattern }
78
- end
79
-
80
- ignore_patterns.any? { |pattern| path =~ pattern }
78
+ _ignore?(path) || (only_patterns && type == :file && !_only?(path))
81
79
  end
82
80
 
83
81
  private
84
82
 
85
- attr_reader :options
83
+ def _ignore?(path)
84
+ ignore_patterns.any? { |pattern| path =~ pattern }
85
+ end
86
+
87
+ def _only?(path)
88
+ only_patterns.any? { |pattern| path =~ pattern }
89
+ end
86
90
 
87
91
  def _init_ignores(ignores, overrides)
88
92
  patterns = []
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Listen
2
4
  class Silencer
3
5
  class Controller
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thread'
4
+
5
+ require_relative 'logger'
6
+
7
+ module Listen
8
+ module Thread
9
+ class << self
10
+ # Creates a new thread with the given name.
11
+ # Any exceptions raised by the thread will be logged with the thread name and complete backtrace.
12
+ # rubocop:disable Style/MultilineBlockChain
13
+ def new(name, &block)
14
+ thread_name = "listen-#{name}"
15
+ caller_stack = caller
16
+
17
+ ::Thread.new do
18
+ rescue_and_log(thread_name, caller_stack: caller_stack, &block)
19
+ end.tap do |thread|
20
+ thread.name = thread_name
21
+ end
22
+ end
23
+ # rubocop:enable Style/MultilineBlockChain
24
+
25
+ def rescue_and_log(method_name, *args, caller_stack: nil)
26
+ yield(*args)
27
+ rescue Exception => exception # rubocop:disable Lint/RescueException
28
+ _log_exception(exception, method_name, caller_stack: caller_stack)
29
+ end
30
+
31
+ private
32
+
33
+ def _log_exception(exception, thread_name, caller_stack: nil)
34
+ complete_backtrace = if caller_stack
35
+ [*exception.backtrace, "--- Thread.new ---", *caller_stack]
36
+ else
37
+ exception.backtrace
38
+ end
39
+ message = "Exception rescued in #{thread_name}:\n#{_exception_with_causes(exception)}\n#{complete_backtrace * "\n"}"
40
+ Listen.logger.error(message)
41
+ end
42
+
43
+ def _exception_with_causes(exception)
44
+ result = +"#{exception.class}: #{exception}"
45
+ if exception.cause
46
+ result << "\n"
47
+ result << "--- Caused by: ---\n"
48
+ result << _exception_with_causes(exception.cause)
49
+ end
50
+ result
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Listen
2
- VERSION = '3.2.1'.freeze
4
+ VERSION = '3.4.1'
3
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.2.1
4
+ version: 3.4.1
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: 2019-12-05 00:00:00.000000000 Z
11
+ date: 2021-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb-fsevent
@@ -50,20 +50,6 @@ dependencies:
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: 0.9.10
53
- - !ruby/object:Gem::Dependency
54
- name: bundler
55
- requirement: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- version: '0'
60
- type: :development
61
- prerelease: false
62
- version_requirements: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: '0'
67
53
  description: The Listen gem listens to file modifications and notifies you about the
68
54
  changes. Works everywhere!
69
55
  email: thibaud@thibaud.gg
@@ -90,16 +76,17 @@ files:
90
76
  - lib/listen/change.rb
91
77
  - lib/listen/cli.rb
92
78
  - lib/listen/directory.rb
79
+ - lib/listen/error.rb
93
80
  - lib/listen/event/config.rb
94
81
  - lib/listen/event/loop.rb
95
82
  - lib/listen/event/processor.rb
96
83
  - lib/listen/event/queue.rb
97
84
  - lib/listen/file.rb
98
85
  - lib/listen/fsm.rb
99
- - lib/listen/internals/thread_pool.rb
100
86
  - lib/listen/listener.rb
101
87
  - lib/listen/listener/config.rb
102
88
  - lib/listen/logger.rb
89
+ - lib/listen/monotonic_time.rb
103
90
  - lib/listen/options.rb
104
91
  - lib/listen/queue_optimizer.rb
105
92
  - lib/listen/record.rb
@@ -107,20 +94,24 @@ files:
107
94
  - lib/listen/record/symlink_detector.rb
108
95
  - lib/listen/silencer.rb
109
96
  - lib/listen/silencer/controller.rb
97
+ - lib/listen/thread.rb
110
98
  - lib/listen/version.rb
111
99
  homepage: https://github.com/guard/listen
112
100
  licenses:
113
101
  - MIT
114
- metadata: {}
102
+ metadata:
103
+ allowed_push_host: https://rubygems.org
104
+ bug_tracker_uri: https://github.com/guard/listen/issues
105
+ changelog_uri: https://github.com/guard/listen/releases
106
+ documentation_uri: https://www.rubydoc.info/gems/listen/3.4.1
107
+ homepage_uri: https://github.com/guard/listen
108
+ source_code_uri: https://github.com/guard/listen/tree/v3.4.1
115
109
  post_install_message:
116
110
  rdoc_options: []
117
111
  require_paths:
118
112
  - lib
119
113
  required_ruby_version: !ruby/object:Gem::Requirement
120
114
  requirements:
121
- - - "~>"
122
- - !ruby/object:Gem::Version
123
- version: '2.2'
124
115
  - - ">="
125
116
  - !ruby/object:Gem::Version
126
117
  version: 2.2.7
@@ -130,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
121
  - !ruby/object:Gem::Version
131
122
  version: '0'
132
123
  requirements: []
133
- rubygems_version: 3.0.6
124
+ rubygems_version: 3.0.1
134
125
  signing_key:
135
126
  specification_version: 4
136
127
  summary: Listen to file modifications
@@ -1,29 +0,0 @@
1
- module Listen
2
- # @private api
3
- module Internals
4
- module ThreadPool
5
- def self.add(&block)
6
- Thread.new { block.call }.tap do |th|
7
- (@threads ||= Queue.new) << th
8
- end
9
- end
10
-
11
- def self.stop
12
- return unless @threads ||= nil
13
- return if @threads.empty? # return to avoid using possibly stubbed Queue
14
-
15
- killed = Queue.new
16
- # You can't kill a read on a descriptor in JRuby, so let's just
17
- # ignore running threads (listen rb-inotify waiting for disk activity
18
- # before closing) pray threads die faster than they are created...
19
- limit = RUBY_ENGINE == 'jruby' ? [1] : []
20
-
21
- killed << @threads.pop.kill until @threads.empty?
22
- until killed.empty?
23
- th = killed.pop
24
- th.join(*limit) unless th[:listen_blocking_read_thread]
25
- end
26
- end
27
- end
28
- end
29
- end