listen 3.7.0 → 3.7.1

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: ff9bdc7fe6e17c76745c2bd710f79322f22ebd7f7274241403f4132a575d2a7a
4
- data.tar.gz: 3868e870e71badf618acb9f50a6d36227f722dd592360e894bb7cc9e2b5feb67
3
+ metadata.gz: 800a9d0af997cb48bc330b0aeaecdcb39b53e9bdeb2dbed6c08fd03b237a3d36
4
+ data.tar.gz: 5caa12c52d09e7447d0f1b43fddadf03e4e33ae4c611bd0ed7d367e3cd3a280b
5
5
  SHA512:
6
- metadata.gz: dbdddb8b8196ed73ae3e23c1bcea1396451bfd2fa36524778bbfbb98dc4565fd248d9035226c286c9feab1b92fddc61c2f0903159c8b4717c9983c535a06da70
7
- data.tar.gz: 9942df50a62c7a88fafe9eea748e611618251db4ca5bf94850585e0529b3c6812f6658c2221c39a7160d72f5f0ce26a207e2fb1feedd404e20a9f0c34365979f
6
+ metadata.gz: 8fa9b8758f30b8ececde07ca321a23fb02c9cfbec59e587011b1598d297f8a0a451728fb394e0bc1fa182e7ef40e4598bfa82b035bdccc29f6375b5df95dda6f
7
+ data.tar.gz: 8b94d5ab7085f27382cfca52d32ff8717c3d17f14ed3632a96853e8e4bcd2174bbc8f5f8f0ff3709f739b13c440fb87a82540bb0ae784395896fb0513837895a
data/README.md CHANGED
@@ -97,23 +97,23 @@ The callback receives **three** array parameters: `modified`, `added` and `remov
97
97
  Each of these three is always an array with 0 or more entries.
98
98
  Each array entry is an absolute path.
99
99
 
100
- ### Pause / unpause / stop
100
+ ### Pause / start / stop
101
101
 
102
- Listeners can also be easily paused/unpaused:
102
+ Listeners can also be easily paused and later un-paused with start:
103
103
 
104
104
  ``` ruby
105
105
  listener = Listen.to('dir/path/to/listen') { |modified, added, removed| puts 'handle changes here...' }
106
106
 
107
107
  listener.start
108
- listener.paused? # => false
108
+ listener.paused? # => false
109
109
  listener.processing? # => true
110
110
 
111
- listener.pause # stops processing changes (but keeps on collecting them)
112
- listener.paused? # => true
111
+ listener.pause # stops processing changes (but keeps on collecting them)
112
+ listener.paused? # => true
113
113
  listener.processing? # => false
114
114
 
115
- listener.unpause # resumes processing changes ("start" would do the same)
116
- listener.stop # stop both listening to changes and processing them
115
+ listener.start # resumes processing changes
116
+ listener.stop # stop both listening to changes and processing them
117
117
  ```
118
118
 
119
119
  Note: While paused, `listen` keeps on collecting changes in the background - to clear them, call `stop`.
@@ -122,7 +122,7 @@ listener.stop # stop both listening to changes and processing them
122
122
 
123
123
  ### Ignore / ignore!
124
124
 
125
- `Listen` ignores some directories and extensions by default (See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer).
125
+ `Listen` ignores some directories and extensions by default (See DEFAULT_IGNORED_FILES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer).
126
126
  You can add ignoring patterns with the `ignore` option/method or overwrite default with `ignore!` option/method.
127
127
 
128
128
  ``` ruby
@@ -157,7 +157,7 @@ All the following options can be set through the `Listen.to` after the directory
157
157
 
158
158
  ```ruby
159
159
  ignore: [%r{/foo/bar}, /\.pid$/, /\.coffee$/] # Ignore a list of paths
160
- # default: See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer
160
+ # default: See DEFAULT_IGNORED_FILES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer
161
161
 
162
162
  ignore!: %r{/foo/bar} # Same as ignore options, but overwrite default ignored paths.
163
163
 
@@ -36,7 +36,7 @@ module Listen
36
36
  end
37
37
 
38
38
  # TODO: this is not tested properly
39
- previous = previous.reject { |entry, _| current.include? path + entry }
39
+ previous = previous.reject { |entry, _| current.include?(path + entry) }
40
40
 
41
41
  _async_changes(snapshot, Pathname.new(rel_path), previous, options)
42
42
  rescue Errno::ENOENT, Errno::EHOSTDOWN
data/lib/listen/record.rb CHANGED
@@ -12,14 +12,14 @@ module Listen
12
12
  attr_reader :root
13
13
 
14
14
  def initialize(directory, silencer)
15
- @tree = _auto_hash
15
+ reset_tree
16
16
  @root = directory.to_s
17
17
  @silencer = silencer
18
18
  end
19
19
 
20
20
  def add_dir(rel_path)
21
- if ![nil, '', '.'].include?(rel_path)
22
- @tree[rel_path] ||= {}
21
+ if !empty_dirname?(rel_path.to_s)
22
+ @tree[rel_path.to_s]
23
23
  end
24
24
  end
25
25
 
@@ -35,32 +35,32 @@ module Listen
35
35
 
36
36
  def file_data(rel_path)
37
37
  dirname, basename = Pathname(rel_path).split.map(&:to_s)
38
- if [nil, '', '.'].include? dirname
39
- @tree[basename] ||= {}
38
+ if empty_dirname?(dirname)
40
39
  @tree[basename].dup
41
40
  else
42
- @tree[dirname] ||= {}
43
41
  @tree[dirname][basename] ||= {}
44
42
  @tree[dirname][basename].dup
45
43
  end
46
44
  end
47
45
 
48
46
  def dir_entries(rel_path)
49
- subtree = if ['', '.'].include? rel_path.to_s
47
+ rel_path_s = rel_path.to_s
48
+ subtree = if empty_dirname?(rel_path_s)
50
49
  @tree
51
50
  else
52
- @tree[rel_path.to_s] ||= _auto_hash
53
- @tree[rel_path.to_s]
51
+ @tree[rel_path_s]
54
52
  end
55
53
 
56
- subtree.transform_values do |values|
57
- # only get data for file entries
58
- values.key?(:mtime) ? values : {}
54
+ subtree.each_with_object({}) do |(key, values), result|
55
+ # only return data for file entries inside the dir (which will each be sub-hashes)
56
+ if values.is_a?(Hash)
57
+ result[key] = values.has_key?(:mtime) ? values : {}
58
+ end
59
59
  end
60
60
  end
61
61
 
62
62
  def build
63
- @tree = _auto_hash
63
+ reset_tree
64
64
  # TODO: test with a file name given
65
65
  # TODO: test other permissions
66
66
  # TODO: test with mixed encoding
@@ -72,15 +72,18 @@ module Listen
72
72
 
73
73
  private
74
74
 
75
- def _auto_hash
76
- Hash.new { |h, k| h[k] = {} }
75
+ def empty_dirname?(dirname)
76
+ dirname == '.' || dirname == ''
77
+ end
78
+
79
+ def reset_tree
80
+ @tree = Hash.new { |h, k| h[k] = {} }
77
81
  end
78
82
 
79
83
  def _fast_update_file(dirname, basename, data)
80
- if [nil, '', '.'].include?(dirname)
81
- @tree[basename] = (@tree[basename] || {}).merge(data)
84
+ if empty_dirname?(dirname.to_s)
85
+ @tree[basename] = @tree[basename].merge(data)
82
86
  else
83
- @tree[dirname] ||= {}
84
87
  @tree[dirname][basename] = (@tree[dirname][basename] || {}).merge(data)
85
88
  end
86
89
  end
@@ -88,7 +91,7 @@ module Listen
88
91
  def _fast_unset_path(dirname, basename)
89
92
  # this may need to be reworked to properly remove
90
93
  # entries from a tree, without adding non-existing dirs to the record
91
- if [nil, '', '.'].include?(dirname)
94
+ if empty_dirname?(dirname.to_s)
92
95
  if @tree.key?(basename)
93
96
  @tree.delete(basename)
94
97
  end
@@ -3,8 +3,8 @@
3
3
  module Listen
4
4
  class Silencer
5
5
  # The default list of directories that get ignored.
6
- DEFAULT_IGNORED_DIRECTORIES = %r{^(?:
7
- \.git
6
+ DEFAULT_IGNORED_FILES = %r{\A(?:
7
+ \.git
8
8
  | \.svn
9
9
  | \.hg
10
10
  | \.rbx
@@ -13,8 +13,12 @@ module Listen
13
13
  | vendor/bundle
14
14
  | log
15
15
  | tmp
16
- |vendor/ruby
17
- )(/|$)}x.freeze
16
+ | vendor/ruby
17
+
18
+ # emacs temp files
19
+ | \#.+\#
20
+ | \.\#.+
21
+ )(/|\z)}x.freeze
18
22
 
19
23
  # The default list of files that get ignored.
20
24
  DEFAULT_IGNORED_EXTENSIONS = %r{(?:
@@ -35,7 +39,7 @@ module Listen
35
39
  | ^4913
36
40
 
37
41
  # Sed temporary files - but without actual words, like 'sedatives'
38
- | (?:^
42
+ | (?:\A
39
43
  sed
40
44
 
41
45
  (?:
@@ -55,7 +59,7 @@ module Listen
55
59
  | \.DS_Store
56
60
  | \.tmp
57
61
  | ~
58
- )$}x.freeze
62
+ )\z}x.freeze
59
63
 
60
64
  # TODO: deprecate these mutators; use attr_reader instead
61
65
  attr_accessor :only_patterns, :ignore_patterns
@@ -89,7 +93,7 @@ module Listen
89
93
  def _init_ignores(ignores, overrides)
90
94
  patterns = []
91
95
  unless overrides
92
- patterns << DEFAULT_IGNORED_DIRECTORIES
96
+ patterns << DEFAULT_IGNORED_FILES
93
97
  patterns << DEFAULT_IGNORED_EXTENSIONS
94
98
  end
95
99
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Listen
4
- VERSION = '3.7.0'
4
+ VERSION = '3.7.1'
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.7.0
4
+ version: 3.7.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: 2021-08-19 00:00:00.000000000 Z
11
+ date: 2022-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb-fsevent
@@ -103,9 +103,9 @@ 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.7.0
106
+ documentation_uri: https://www.rubydoc.info/gems/listen/3.7.1
107
107
  homepage_uri: https://github.com/guard/listen
108
- source_code_uri: https://github.com/guard/listen/tree/v3.7.0
108
+ source_code_uri: https://github.com/guard/listen/tree/v3.7.1
109
109
  post_install_message:
110
110
  rdoc_options: []
111
111
  require_paths: