listen 2.0.4 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -2
- data/README.md +2 -0
- data/lib/listen/adapter.rb +1 -5
- data/lib/listen/adapter/bsd.rb +2 -1
- data/lib/listen/adapter/windows.rb +2 -1
- data/lib/listen/listener.rb +7 -6
- data/lib/listen/silencer.rb +12 -7
- data/lib/listen/version.rb +1 -1
- data/spec/lib/listen/adapter_spec.rb +35 -43
- data/spec/lib/listen/listener_spec.rb +12 -7
- data/spec/lib/listen/silencer_spec.rb +7 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b358ff4d6b7a68de70fe803dfc173fe5b8c52ed8
|
4
|
+
data.tar.gz: 59d00886af43fd6d7ee5c72d9cbdd865713ee041
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36e89ba4d2df71211e6ece83b8f27384273a4c68b8efa85a0adf751d486f0a2579a5d0480c2e0022a0534ae44f52361d09477cce0619daf7e58e1d8fad8e8ad6
|
7
|
+
data.tar.gz: b1414149c17f0cd68af1d9c5ed181d0d477095cb6cf6719c3cbd0f2e1d32221fd2729df3c171cbe3340188eb3f2b42d8d68ed3aa22199945651678b5d4a3a16c
|
data/.travis.yml
CHANGED
@@ -4,14 +4,16 @@ rvm:
|
|
4
4
|
- 1.9.3
|
5
5
|
- 2.0.0
|
6
6
|
- jruby-19mode
|
7
|
+
- jruby-head
|
7
8
|
- rbx-19mode
|
9
|
+
- rbx-head
|
8
10
|
matrix:
|
9
11
|
allow_failures:
|
10
12
|
- rvm: jruby-19mode
|
13
|
+
- rvm: jruby-head
|
11
14
|
- rvm: rbx-19mode
|
15
|
+
- rvm: rbx-head
|
12
16
|
notifications:
|
13
17
|
recipients:
|
14
18
|
- thibaud@thibaud.me
|
15
19
|
- remy@rymai.me
|
16
|
-
- michi@netzpiraten.ch
|
17
|
-
- maher@sallam.me
|
data/README.md
CHANGED
@@ -70,6 +70,8 @@ listener.ignore /\.rb/ # ignore rb extension in addition of pkg.
|
|
70
70
|
sleep
|
71
71
|
```
|
72
72
|
|
73
|
+
Note: Ignoring regexp patterns are evaluated against relative paths.
|
74
|
+
|
73
75
|
## Changes callback
|
74
76
|
|
75
77
|
Changes to the listened-to directories gets reported back to the user in a callback.
|
data/lib/listen/adapter.rb
CHANGED
@@ -18,7 +18,7 @@ module Listen
|
|
18
18
|
private
|
19
19
|
|
20
20
|
def self._select(options)
|
21
|
-
return Polling if options[:force_polling]
|
21
|
+
return Polling if options[:force_polling]
|
22
22
|
return _usable_adapter_class if _usable_adapter_class
|
23
23
|
|
24
24
|
_warn_polling_fallback(options)
|
@@ -36,9 +36,5 @@ module Listen
|
|
36
36
|
warning = options.fetch(:polling_fallback_message, POLLING_FALLBACK_MESSAGE)
|
37
37
|
Kernel.warn "[Listen warning]:\n#{warning.gsub(/^(.*)/, ' \1')}"
|
38
38
|
end
|
39
|
-
|
40
|
-
def self.not_mri?
|
41
|
-
RUBY_ENGINE != 'ruby'
|
42
|
-
end
|
43
39
|
end
|
44
40
|
end
|
data/lib/listen/adapter/bsd.rb
CHANGED
data/lib/listen/listener.rb
CHANGED
@@ -81,8 +81,8 @@ module Listen
|
|
81
81
|
# @param [Regexp, Hash<Regexp>] new ignoring patterns.
|
82
82
|
#
|
83
83
|
def ignore(regexps)
|
84
|
-
options[:ignore] = [options[:ignore], regexps]
|
85
|
-
Celluloid::Actor[:listen_silencer] = Silencer.new(
|
84
|
+
@options[:ignore] = [options[:ignore], regexps]
|
85
|
+
Celluloid::Actor[:listen_silencer] = Silencer.new(self)
|
86
86
|
end
|
87
87
|
|
88
88
|
# Overwrites ignore patterns (See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer)
|
@@ -90,9 +90,9 @@ module Listen
|
|
90
90
|
# @param [Regexp, Hash<Regexp>] new ignoring patterns.
|
91
91
|
#
|
92
92
|
def ignore!(regexps)
|
93
|
-
options.delete(:ignore)
|
94
|
-
options[:ignore!] = regexps
|
95
|
-
Celluloid::Actor[:listen_silencer] = Silencer.new(
|
93
|
+
@options.delete(:ignore)
|
94
|
+
@options[:ignore!] = regexps
|
95
|
+
Celluloid::Actor[:listen_silencer] = Silencer.new(self)
|
96
96
|
end
|
97
97
|
|
98
98
|
private
|
@@ -113,13 +113,14 @@ module Listen
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def _init_actors
|
116
|
-
Celluloid::Actor[:listen_silencer] = Silencer.new(
|
116
|
+
Celluloid::Actor[:listen_silencer] = Silencer.new(self)
|
117
117
|
Celluloid::Actor[:listen_change_pool] = Change.pool(args: self)
|
118
118
|
Celluloid::Actor[:listen_adapter] = Adapter.new(self)
|
119
119
|
Celluloid::Actor[:listen_record] = Record.new(self)
|
120
120
|
end
|
121
121
|
|
122
122
|
def _signals_trap
|
123
|
+
return if defined?(JRUBY_VERSION)
|
123
124
|
if Signal.list.keys.include?('INT')
|
124
125
|
Signal.trap('INT') { stop }
|
125
126
|
end
|
data/lib/listen/silencer.rb
CHANGED
@@ -8,23 +8,23 @@ module Listen
|
|
8
8
|
# The default list of files that get ignored.
|
9
9
|
DEFAULT_IGNORED_EXTENSIONS = %w[.DS_Store]
|
10
10
|
|
11
|
-
attr_accessor :
|
11
|
+
attr_accessor :listener, :patterns
|
12
12
|
|
13
|
-
def initialize(
|
14
|
-
@
|
13
|
+
def initialize(listener)
|
14
|
+
@listener = listener
|
15
15
|
_init_patterns
|
16
16
|
end
|
17
17
|
|
18
18
|
def silenced?(path)
|
19
|
-
patterns.any? { |pattern| path
|
19
|
+
patterns.any? { |pattern| _relative_path(path) =~ pattern }
|
20
20
|
end
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def _init_patterns
|
25
25
|
@patterns = []
|
26
|
-
@patterns << _default_patterns unless options[:ignore!]
|
27
|
-
@patterns << options[:ignore] << options[:ignore!]
|
26
|
+
@patterns << _default_patterns unless listener.options[:ignore!]
|
27
|
+
@patterns << listener.options[:ignore] << listener.options[:ignore!]
|
28
28
|
@patterns.compact!
|
29
29
|
@patterns.flatten!
|
30
30
|
end
|
@@ -35,12 +35,17 @@ module Listen
|
|
35
35
|
|
36
36
|
def _default_ignored_directories_patterns
|
37
37
|
ignored_directories = DEFAULT_IGNORED_DIRECTORIES.map { |d| Regexp.escape(d) }
|
38
|
-
%r{
|
38
|
+
%r{^(?:#{ignored_directories.join('|')})(/|$)}
|
39
39
|
end
|
40
40
|
|
41
41
|
def _default_ignored_extensions_patterns
|
42
42
|
ignored_extensions = DEFAULT_IGNORED_EXTENSIONS.map { |e| Regexp.escape(e) }
|
43
43
|
%r{(?:#{ignored_extensions.join('|')})$}
|
44
44
|
end
|
45
|
+
|
46
|
+
def _relative_path(path)
|
47
|
+
relative_paths = listener.directories.map { |dir| path.relative_path_from(dir).to_s }
|
48
|
+
relative_paths.detect { |path| !path.start_with?('../') }
|
49
|
+
end
|
45
50
|
end
|
46
51
|
end
|
data/lib/listen/version.rb
CHANGED
@@ -16,62 +16,54 @@ describe Listen::Adapter do
|
|
16
16
|
expect(adapter).to be_kind_of Listen::Adapter::Polling
|
17
17
|
end
|
18
18
|
|
19
|
-
it "returns
|
20
|
-
|
19
|
+
it "returns BSD adapter when usable" do
|
20
|
+
Listen::Adapter::BSD.stub(:usable?) { true }
|
21
|
+
expect(Listen::Adapter::BSD).to receive(:new)
|
22
|
+
adapter
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns Darwin adapter when usable" do
|
26
|
+
Listen::Adapter::Darwin.stub(:usable?) { true }
|
27
|
+
expect(Listen::Adapter::Darwin).to receive(:new)
|
28
|
+
adapter
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns Linux adapter when usable" do
|
21
32
|
Listen::Adapter::Linux.stub(:usable?) { true }
|
22
|
-
expect(
|
33
|
+
expect(Listen::Adapter::Linux).to receive(:new)
|
34
|
+
adapter
|
23
35
|
end
|
24
36
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
37
|
+
it "returns Windows adapter when usable" do
|
38
|
+
Listen::Adapter::Windows.stub(:usable?) { true }
|
39
|
+
expect(Listen::Adapter::Windows).to receive(:new)
|
40
|
+
adapter
|
41
|
+
end
|
31
42
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
43
|
+
context "no usable adapters" do
|
44
|
+
before { Kernel.stub(:warn) }
|
45
|
+
|
46
|
+
it "returns Polling adapter" do
|
47
|
+
expect(adapter).to be_kind_of Listen::Adapter::Polling
|
36
48
|
end
|
37
49
|
|
38
|
-
it "
|
39
|
-
|
40
|
-
expect(Listen::Adapter::Linux).to receive(:new)
|
50
|
+
it "warns polling fallback with default message" do
|
51
|
+
expect(Kernel).to receive(:warn).with("[Listen warning]:\n #{described_class::POLLING_FALLBACK_MESSAGE}")
|
41
52
|
adapter
|
42
53
|
end
|
43
54
|
|
44
|
-
it "
|
45
|
-
|
46
|
-
expect(
|
55
|
+
it "doesn't warn if polling_fallback_message is false" do
|
56
|
+
listener.stub(:options) { { polling_fallback_message: false } }
|
57
|
+
expect(Kernel).to_not receive(:warn)
|
47
58
|
adapter
|
48
59
|
end
|
49
60
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
expect(adapter).to be_kind_of Listen::Adapter::Polling
|
55
|
-
end
|
56
|
-
|
57
|
-
it "warns polling fallback with default message" do
|
58
|
-
expect(Kernel).to receive(:warn).with("[Listen warning]:\n #{described_class::POLLING_FALLBACK_MESSAGE}")
|
59
|
-
adapter
|
60
|
-
end
|
61
|
-
|
62
|
-
it "doesn't warn if polling_fallback_message is false" do
|
63
|
-
listener.stub(:options) { { polling_fallback_message: false } }
|
64
|
-
expect(Kernel).to_not receive(:warn)
|
65
|
-
adapter
|
66
|
-
end
|
67
|
-
|
68
|
-
it "warns polling fallback with custom message if set" do
|
69
|
-
listener.stub(:options) { { polling_fallback_message: 'custom fallback message' } }
|
70
|
-
expect(Kernel).to receive(:warn).with("[Listen warning]:\n custom fallback message")
|
71
|
-
adapter
|
72
|
-
end
|
61
|
+
it "warns polling fallback with custom message if set" do
|
62
|
+
listener.stub(:options) { { polling_fallback_message: 'custom fallback message' } }
|
63
|
+
expect(Kernel).to receive(:warn).with("[Listen warning]:\n custom fallback message")
|
64
|
+
adapter
|
73
65
|
end
|
74
66
|
end
|
75
|
-
|
67
|
+
end
|
76
68
|
|
77
69
|
end
|
@@ -68,7 +68,7 @@ describe Listen::Listener do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it "registers silencer" do
|
71
|
-
expect(Listen::Silencer).to receive(:new).with(listener
|
71
|
+
expect(Listen::Silencer).to receive(:new).with(listener) { silencer }
|
72
72
|
expect(Celluloid::Actor).to receive(:[]=).with(:listen_silencer, silencer)
|
73
73
|
listener.start
|
74
74
|
end
|
@@ -190,7 +190,7 @@ describe Listen::Listener do
|
|
190
190
|
before { Celluloid::Actor.stub(:[]=) }
|
191
191
|
|
192
192
|
it "resets silencer actor with new pattern" do
|
193
|
-
expect(Listen::Silencer).to receive(:new).with(
|
193
|
+
expect(Listen::Silencer).to receive(:new).with(listener) { new_silencer }
|
194
194
|
expect(Celluloid::Actor).to receive(:[]=).with(:listen_silencer, new_silencer)
|
195
195
|
listener.ignore(/foo/)
|
196
196
|
end
|
@@ -199,8 +199,9 @@ describe Listen::Listener do
|
|
199
199
|
let(:options) { { ignore: /bar/ } }
|
200
200
|
|
201
201
|
it "adds up to existing ignore options" do
|
202
|
-
expect(Listen::Silencer).to receive(:new).with(
|
202
|
+
expect(Listen::Silencer).to receive(:new).with(listener)
|
203
203
|
listener.ignore(/foo/)
|
204
|
+
expect(listener.options).to include(ignore: [/bar/, /foo/])
|
204
205
|
end
|
205
206
|
end
|
206
207
|
|
@@ -208,8 +209,9 @@ describe Listen::Listener do
|
|
208
209
|
let(:options) { { ignore: [/bar/] } }
|
209
210
|
|
210
211
|
it "adds up to existing ignore options" do
|
211
|
-
expect(Listen::Silencer).to receive(:new).with(
|
212
|
+
expect(Listen::Silencer).to receive(:new).with(listener)
|
212
213
|
listener.ignore(/foo/)
|
214
|
+
expect(listener.options).to include(ignore: [[/bar/], /foo/])
|
213
215
|
end
|
214
216
|
end
|
215
217
|
end
|
@@ -219,17 +221,19 @@ describe Listen::Listener do
|
|
219
221
|
before { Celluloid::Actor.stub(:[]=) }
|
220
222
|
|
221
223
|
it "resets silencer actor with new pattern" do
|
222
|
-
expect(Listen::Silencer).to receive(:new).with(
|
224
|
+
expect(Listen::Silencer).to receive(:new).with(listener) { new_silencer }
|
223
225
|
expect(Celluloid::Actor).to receive(:[]=).with(:listen_silencer, new_silencer)
|
224
226
|
listener.ignore!(/foo/)
|
227
|
+
expect(listener.options).to include(ignore!: /foo/)
|
225
228
|
end
|
226
229
|
|
227
230
|
context "with existing ignore! options" do
|
228
231
|
let(:options) { { ignore!: /bar/ } }
|
229
232
|
|
230
233
|
it "overwrites existing ignore options" do
|
231
|
-
expect(Listen::Silencer).to receive(:new).with(
|
234
|
+
expect(Listen::Silencer).to receive(:new).with(listener)
|
232
235
|
listener.ignore!([/foo/])
|
236
|
+
expect(listener.options).to include(ignore!: [/foo/])
|
233
237
|
end
|
234
238
|
end
|
235
239
|
|
@@ -237,8 +241,9 @@ describe Listen::Listener do
|
|
237
241
|
let(:options) { { ignore: /bar/ } }
|
238
242
|
|
239
243
|
it "deletes ignore options" do
|
240
|
-
expect(Listen::Silencer).to receive(:new).with(
|
244
|
+
expect(Listen::Silencer).to receive(:new).with(listener)
|
241
245
|
listener.ignore!([/foo/])
|
246
|
+
expect(listener.options).to_not include(ignore: /bar/)
|
242
247
|
end
|
243
248
|
end
|
244
249
|
end
|
@@ -1,10 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Listen::Silencer do
|
4
|
-
let(:
|
4
|
+
let(:options) { {} }
|
5
|
+
let(:listener) { double(Listen::Listener,
|
6
|
+
directories: [Pathname.new(Dir.pwd), Pathname.new("/Users/Shared/")],
|
7
|
+
options: options
|
8
|
+
) }
|
9
|
+
let(:silencer) { Listen::Silencer.new(listener) }
|
5
10
|
|
6
11
|
describe "#silenced?" do
|
7
|
-
let(:options) { {} }
|
8
12
|
let(:pwd) { Pathname.new(Dir.pwd) }
|
9
13
|
|
10
14
|
context "default ignore" do
|
@@ -46,7 +50,7 @@ describe Listen::Silencer do
|
|
46
50
|
end
|
47
51
|
|
48
52
|
context "with ignore options" do
|
49
|
-
let(:options) { { ignore: [%r{foo/bar}, /\.pid$/] } }
|
53
|
+
let(:options) { { ignore: [%r{^foo/bar}, /\.pid$/] } }
|
50
54
|
|
51
55
|
it "silences custom ignored directory" do
|
52
56
|
path = pwd.join('foo', 'bar')
|
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: 2.0
|
4
|
+
version: 2.1.0
|
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: 2013-10-
|
11
|
+
date: 2013-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid
|
@@ -181,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
181
|
version: '0'
|
182
182
|
requirements: []
|
183
183
|
rubyforge_project:
|
184
|
-
rubygems_version: 2.1.
|
184
|
+
rubygems_version: 2.1.8
|
185
185
|
signing_key:
|
186
186
|
specification_version: 4
|
187
187
|
summary: Listen to file modifications
|