listen 2.7.0 → 2.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/listen/listener.rb +19 -10
- data/lib/listen/version.rb +1 -1
- data/spec/acceptance/tcp_spec.rb +5 -5
- data/spec/lib/listen/adapter/polling_spec.rb +1 -1
- data/spec/lib/listen/listener_spec.rb +31 -1
- data/spec/support/acceptance_helper.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15c303b4292e7a0d6c1406f08354026a6afce90d
|
4
|
+
data.tar.gz: 72470e17d6c39b4c72b46685eec317db75d2478a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69afc0f874fe99bcb8c43ba6c42264219484ef59802f6a1daa8ebf84d5b2134b5b3ed29a5570a07358de710d343d3b0b2ff0420d76adc9c5b2987f4e0fc99d84
|
7
|
+
data.tar.gz: d63742fbc8b428ca7837a5d9549545d061ea1d0351b89e475be9614c7eb67872247b187e1b777eda93ce16a979905350a54d23fa0032f5f751c7cfe8fc316340
|
data/.gitignore
CHANGED
data/lib/listen/listener.rb
CHANGED
@@ -138,11 +138,16 @@ module Listen
|
|
138
138
|
loop do
|
139
139
|
break if @stopping
|
140
140
|
|
141
|
-
changes =
|
142
|
-
|
143
|
-
|
141
|
+
changes = []
|
142
|
+
begin
|
143
|
+
sleep options[:wait_for_delay] # wait for changes to accumulate
|
144
|
+
new_changes = _pop_changes
|
145
|
+
changes += new_changes
|
146
|
+
end until new_changes.empty?
|
147
|
+
unless changes.empty?
|
148
|
+
hash = _smoosh_changes(changes)
|
149
|
+
block.call(hash[:modified], hash[:added], hash[:removed])
|
144
150
|
end
|
145
|
-
sleep options[:wait_for_delay]
|
146
151
|
end
|
147
152
|
rescue => ex
|
148
153
|
Kernel.warn "[Listen warning]: Change block raised an exception: #{$!}"
|
@@ -150,12 +155,16 @@ module Listen
|
|
150
155
|
end
|
151
156
|
|
152
157
|
def _pop_changes
|
153
|
-
|
154
|
-
until @changes.empty?
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
158
|
+
popped = []
|
159
|
+
popped << @changes.pop until @changes.empty?
|
160
|
+
popped
|
161
|
+
end
|
162
|
+
|
163
|
+
def _smoosh_changes(changes)
|
164
|
+
smooshed = { modified: [], added: [], removed: [] }
|
165
|
+
changes.each { |h| type = h.keys.first; smooshed[type] << h[type].to_s }
|
166
|
+
smooshed.each { |_, v| v.uniq! }
|
167
|
+
smooshed
|
159
168
|
end
|
160
169
|
end
|
161
170
|
end
|
data/lib/listen/version.rb
CHANGED
data/spec/acceptance/tcp_spec.rb
CHANGED
@@ -86,7 +86,7 @@ describe Listen::TCP do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'receives changes over TCP' do
|
89
|
-
expect(listen {
|
89
|
+
expect(listen(1) {
|
90
90
|
touch 'file.rb'
|
91
91
|
}).to eq(
|
92
92
|
modified: [],
|
@@ -98,7 +98,7 @@ describe Listen::TCP do
|
|
98
98
|
it 'may be paused and unpaused' do
|
99
99
|
recipient.pause
|
100
100
|
|
101
|
-
expect(listen {
|
101
|
+
expect(listen(1) {
|
102
102
|
touch 'file.rb'
|
103
103
|
}).to eq(
|
104
104
|
modified: [],
|
@@ -108,7 +108,7 @@ describe Listen::TCP do
|
|
108
108
|
|
109
109
|
recipient.unpause
|
110
110
|
|
111
|
-
expect(listen {
|
111
|
+
expect(listen(1) {
|
112
112
|
touch 'file.rb'
|
113
113
|
}).to eq(
|
114
114
|
modified: ['file.rb'],
|
@@ -120,7 +120,7 @@ describe Listen::TCP do
|
|
120
120
|
it 'may be stopped and restarted' do
|
121
121
|
recipient.stop
|
122
122
|
|
123
|
-
expect(listen {
|
123
|
+
expect(listen(1) {
|
124
124
|
touch 'file.rb'
|
125
125
|
}).to eq(
|
126
126
|
modified: [],
|
@@ -130,7 +130,7 @@ describe Listen::TCP do
|
|
130
130
|
|
131
131
|
recipient.start
|
132
132
|
|
133
|
-
expect(listen {
|
133
|
+
expect(listen(1) {
|
134
134
|
touch 'file.rb'
|
135
135
|
}).to eq(
|
136
136
|
modified: ['file.rb'],
|
@@ -27,7 +27,7 @@ describe Listen::Adapter::Polling do
|
|
27
27
|
it "notifies change on every listener directories path" do
|
28
28
|
expect(change_pool_async).to receive(:change).with('directory_path', type: 'Dir', recursive: true)
|
29
29
|
t = Thread.new { adapter.start }
|
30
|
-
sleep 0.
|
30
|
+
sleep 0.25
|
31
31
|
t.kill
|
32
32
|
end
|
33
33
|
end
|
@@ -114,7 +114,7 @@ describe Listen::Listener do
|
|
114
114
|
listener.block = block_stub
|
115
115
|
expect(block_stub).to receive(:call).with(['foo'], [], [])
|
116
116
|
listener.start
|
117
|
-
sleep 0.
|
117
|
+
sleep 0.25
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
@@ -268,4 +268,34 @@ describe Listen::Listener do
|
|
268
268
|
end
|
269
269
|
end
|
270
270
|
|
271
|
+
describe '_wait_for_changes' do
|
272
|
+
it 'gets two changes and calls the block once' do
|
273
|
+
|
274
|
+
fake_time = 0
|
275
|
+
listener.stub(:sleep) { |sec| fake_time += sec; listener.stopping = true if fake_time > 1 }
|
276
|
+
|
277
|
+
listener.block = proc { |modified, added, removed|
|
278
|
+
expect(modified).to eql(['foo.txt'])
|
279
|
+
expect(added).to eql(['bar.txt'])
|
280
|
+
}
|
281
|
+
|
282
|
+
i = 0
|
283
|
+
listener.stub(:_pop_changes) do
|
284
|
+
i+=1
|
285
|
+
case i
|
286
|
+
when 1
|
287
|
+
[]
|
288
|
+
when 2
|
289
|
+
[{modified: 'foo.txt'}]
|
290
|
+
when 3
|
291
|
+
[{added: 'bar.txt'}]
|
292
|
+
else
|
293
|
+
[]
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
listener.send :_wait_for_changes
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
271
301
|
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: 2.7.
|
4
|
+
version: 2.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: 2014-03-
|
11
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid
|