listen 3.3.0.pre.2 → 3.3.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.
@@ -62,7 +62,7 @@ module Listen
62
62
  actions << :added if actions.delete(:moved_to)
63
63
  actions << :removed if actions.delete(:moved_from)
64
64
 
65
- modified = actions.detect { |x| x == :modified }
65
+ modified = actions.find { |x| x == :modified }
66
66
  _calculate_add_remove_difference(actions, path, modified)
67
67
  end
68
68
 
@@ -91,10 +91,8 @@ module Listen
91
91
  def _reinterpret_related_changes(cookies)
92
92
  table = { moved_to: :added, moved_from: :removed }
93
93
  cookies.flat_map do |_, changes|
94
- data = _detect_possible_editor_save(changes)
95
- if data
96
- to_dir, to_file = data
97
- [[:modified, to_dir, to_file]]
94
+ if (editor_modified = editor_modified?(changes))
95
+ [[:modified, *editor_modified]]
98
96
  else
99
97
  not_silenced = changes.reject do |type, _, _, path, _|
100
98
  config.silenced?(Pathname(path), type)
@@ -106,7 +104,7 @@ module Listen
106
104
  end
107
105
  end
108
106
 
109
- def _detect_possible_editor_save(changes)
107
+ def editor_modified?(changes)
110
108
  return unless changes.size == 2
111
109
 
112
110
  from_type = from = nil
@@ -118,17 +116,14 @@ module Listen
118
116
  from_type, _from_change, _, from, = data
119
117
  when :moved_to
120
118
  to_type, _to_change, to_dir, to, = data
121
- else
122
- return nil
123
119
  end
124
120
  end
125
121
 
126
- return unless from && to
127
-
128
122
  # Expect an ignored moved_from and non-ignored moved_to
129
123
  # to qualify as an "editor modify"
130
- return unless config.silenced?(Pathname(from), from_type)
131
- config.silenced?(Pathname(to), to_type) ? nil : [to_dir, to]
124
+ if from && to && config.silenced?(Pathname(from), from_type) && !config.silenced?(Pathname(to), to_type)
125
+ [to_dir, to]
126
+ end
132
127
  end
133
128
  end
134
129
  end
@@ -10,14 +10,16 @@ module Listen
10
10
  # TODO: deprecate
11
11
 
12
12
  attr_reader :root
13
+
13
14
  def initialize(directory)
14
15
  @tree = _auto_hash
15
16
  @root = directory.to_s
16
17
  end
17
18
 
18
19
  def add_dir(rel_path)
19
- return if [nil, '', '.'].include? rel_path
20
- @tree[rel_path] ||= {}
20
+ if ![nil, '', '.'].include?(rel_path)
21
+ @tree[rel_path] ||= {}
22
+ end
21
23
  end
22
24
 
23
25
  def update_file(rel_path, data)
@@ -33,33 +35,30 @@ module Listen
33
35
  def file_data(rel_path)
34
36
  dirname, basename = Pathname(rel_path).split.map(&:to_s)
35
37
  if [nil, '', '.'].include? dirname
36
- tree[basename] ||= {}
37
- tree[basename].dup
38
+ @tree[basename] ||= {}
39
+ @tree[basename].dup
38
40
  else
39
- tree[dirname] ||= {}
40
- tree[dirname][basename] ||= {}
41
- tree[dirname][basename].dup
41
+ @tree[dirname] ||= {}
42
+ @tree[dirname][basename] ||= {}
43
+ @tree[dirname][basename].dup
42
44
  end
43
45
  end
44
46
 
45
47
  def dir_entries(rel_path)
46
- subtree =
47
- if [nil, '', '.'].include? rel_path.to_s
48
- tree
49
- else
50
- _sub_tree(rel_path)
51
- end
48
+ subtree = if [nil, '', '.'].include? rel_path.to_s
49
+ @tree
50
+ else
51
+ _sub_tree(rel_path)
52
+ end
52
53
 
53
- result = {}
54
- subtree.each do |key, values|
54
+ subtree.transform_values do |values|
55
55
  # only get data for file entries
56
- result[key] = values.key?(:mtime) ? values : {}
56
+ values.key?(:mtime) ? values : {}
57
57
  end
58
- result
59
58
  end
60
59
 
61
60
  def _sub_tree(rel_path)
62
- tree.each_with_object({}) do |(path, meta), result|
61
+ @tree.each_with_object({}) do |(path, meta), result|
63
62
  next unless path.start_with?(rel_path)
64
63
 
65
64
  if path == rel_path
@@ -85,29 +84,27 @@ module Listen
85
84
  private
86
85
 
87
86
  def _auto_hash
88
- Hash.new { |h, k| h[k] = Hash.new }
87
+ Hash.new { |h, k| h[k] = {} }
89
88
  end
90
89
 
91
- attr_reader :tree
92
-
93
90
  def _fast_update_file(dirname, basename, data)
94
- if [nil, '', '.'].include? dirname
95
- tree[basename] = (tree[basename] || {}).merge(data)
91
+ if [nil, '', '.'].include?(dirname)
92
+ @tree[basename] = (@tree[basename] || {}).merge(data)
96
93
  else
97
- tree[dirname] ||= {}
98
- tree[dirname][basename] = (tree[dirname][basename] || {}).merge(data)
94
+ @tree[dirname] ||= {}
95
+ @tree[dirname][basename] = (@tree[dirname][basename] || {}).merge(data)
99
96
  end
100
97
  end
101
98
 
102
99
  def _fast_unset_path(dirname, basename)
103
100
  # this may need to be reworked to properly remove
104
101
  # entries from a tree, without adding non-existing dirs to the record
105
- if [nil, '', '.'].include? dirname
106
- return unless tree.key?(basename)
107
- tree.delete(basename)
108
- else
109
- return unless tree.key?(dirname)
110
- tree[dirname].delete(basename)
102
+ if [nil, '', '.'].include?(dirname)
103
+ if @tree.key?(basename)
104
+ @tree.delete(basename)
105
+ end
106
+ elsif @tree.key?(dirname)
107
+ @tree[dirname].delete(basename)
111
108
  end
112
109
  end
113
110
 
@@ -17,7 +17,7 @@ module Listen
17
17
 
18
18
  def children
19
19
  child_relative = _join
20
- (_entries(sys_path) - %w(. ..)).map do |name|
20
+ (_entries(sys_path) - %w[. ..]).map do |name|
21
21
  Entry.new(@root, child_relative, name)
22
22
  end
23
23
  end
@@ -6,9 +6,9 @@ module Listen
6
6
  # @private api
7
7
  class Record
8
8
  class SymlinkDetector
9
- WIKI = 'https://github.com/guard/listen/wiki/Duplicate-directory-errors'.freeze
9
+ WIKI = 'https://github.com/guard/listen/wiki/Duplicate-directory-errors'
10
10
 
11
- SYMLINK_LOOP_ERROR = <<-EOS.freeze
11
+ SYMLINK_LOOP_ERROR = <<-EOS
12
12
  ** ERROR: directory is already being watched! **
13
13
 
14
14
  Directory: %s
@@ -33,8 +33,8 @@ module Listen
33
33
  private
34
34
 
35
35
  def _fail(symlinked, real_path)
36
- STDERR.puts format(SYMLINK_LOOP_ERROR, symlinked, real_path)
37
- fail Error, 'Failed due to looped symlinks'
36
+ warn(format(SYMLINK_LOOP_ERROR, symlinked, real_path))
37
+ raise Error, 'Failed due to looped symlinks'
38
38
  end
39
39
  end
40
40
  end
@@ -14,7 +14,7 @@ module Listen
14
14
  | log
15
15
  | tmp
16
16
  |vendor/ruby
17
- )(/|$)}x
17
+ )(/|$)}x.freeze
18
18
 
19
19
  # The default list of files that get ignored.
20
20
  DEFAULT_IGNORED_EXTENSIONS = %r{(?:
@@ -55,7 +55,7 @@ module Listen
55
55
  | \.DS_Store
56
56
  | \.tmp
57
57
  | ~
58
- )$}x
58
+ )$}x.freeze
59
59
 
60
60
  attr_accessor :only_patterns, :ignore_patterns
61
61
 
@@ -75,16 +75,18 @@ module Listen
75
75
  def silenced?(relative_path, type)
76
76
  path = relative_path.to_s
77
77
 
78
- if only_patterns && type == :file
79
- return true unless only_patterns.any? { |pattern| path =~ pattern }
80
- end
81
-
82
- ignore_patterns.any? { |pattern| path =~ pattern }
78
+ _ignore?(path) || (only_patterns && type == :file && !_only?(path))
83
79
  end
84
80
 
85
81
  private
86
82
 
87
- 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
88
90
 
89
91
  def _init_ignores(ignores, overrides)
90
92
  patterns = []
@@ -9,36 +9,43 @@ module Listen
9
9
  class << self
10
10
  # Creates a new thread with the given name.
11
11
  # Any exceptions raised by the thread will be logged with the thread name and complete backtrace.
12
- def new(name)
12
+ # rubocop:disable Style/MultilineBlockChain
13
+ def new(name, &block)
13
14
  thread_name = "listen-#{name}"
14
-
15
15
  caller_stack = caller
16
+
16
17
  ::Thread.new do
17
- begin
18
- yield
19
- rescue Exception => ex
20
- _log_exception(ex, thread_name, caller_stack)
21
- nil
22
- end
18
+ rescue_and_log(thread_name, caller_stack: caller_stack, &block)
23
19
  end.tap do |thread|
24
20
  thread.name = thread_name
25
21
  end
26
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
27
30
 
28
31
  private
29
32
 
30
- def _log_exception(ex, thread_name, caller_stack)
31
- complete_backtrace = [*ex.backtrace, "--- Thread.new ---", *caller_stack]
32
- message = "Exception rescued in #{thread_name}:\n#{_exception_with_causes(ex)}\n#{complete_backtrace * "\n"}"
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"}"
33
40
  Listen.logger.error(message)
34
41
  end
35
42
 
36
- def _exception_with_causes(ex)
37
- result = +"#{ex.class}: #{ex}"
38
- if ex.cause
43
+ def _exception_with_causes(exception)
44
+ result = +"#{exception.class}: #{exception}"
45
+ if exception.cause
39
46
  result << "\n"
40
47
  result << "--- Caused by: ---\n"
41
- result << _exception_with_causes(ex.cause)
48
+ result << _exception_with_causes(exception.cause)
42
49
  end
43
50
  result
44
51
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Listen
4
- VERSION = '3.3.0.pre.2'
4
+ VERSION = '3.3.3'
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.3.0.pre.2
4
+ version: 3.3.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-10-31 00:00:00.000000000 Z
11
+ date: 2020-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb-fsevent
@@ -51,7 +51,7 @@ dependencies:
51
51
  - !ruby/object:Gem::Version
52
52
  version: 0.9.10
53
53
  description: The Listen gem listens to file modifications and notifies you about the
54
- changegem. Works everywhere!
54
+ changes. Works everywhere!
55
55
  email: thibaud@thibaud.gg
56
56
  executables:
57
57
  - listen
@@ -99,6 +99,12 @@ licenses:
99
99
  - MIT
100
100
  metadata:
101
101
  allowed_push_host: https://rubygems.org
102
+ bug_tracker_uri: https://github.com/guard/listen/issues
103
+ changelog_uri: https://github.com/guard/listen/releases
104
+ documentation_uri: https://www.rubydoc.info/gems/listen/3.3.3
105
+ homepage_uri: https://github.com/guard/listen
106
+ source_code_uri: https://github.com/guard/listen/tree/v3.3.3
107
+ wiki_uri: https://github.com/guard/listen/wiki
102
108
  post_install_message:
103
109
  rdoc_options: []
104
110
  require_paths:
@@ -110,9 +116,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
116
  version: 2.2.7
111
117
  required_rubygems_version: !ruby/object:Gem::Requirement
112
118
  requirements:
113
- - - ">"
119
+ - - ">="
114
120
  - !ruby/object:Gem::Version
115
- version: 1.3.1
121
+ version: '0'
116
122
  requirements: []
117
123
  rubygems_version: 3.0.1
118
124
  signing_key: