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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac6fd4b57871600c33db9f04c53928b0aa538ab0
4
- data.tar.gz: dc7c7574fc2d091abfc188e8de6407f3cdb1b39c
3
+ metadata.gz: 15c303b4292e7a0d6c1406f08354026a6afce90d
4
+ data.tar.gz: 72470e17d6c39b4c72b46685eec317db75d2478a
5
5
  SHA512:
6
- metadata.gz: 1cff1bc85b3d9c2e0d65be6b943d4ef5adf5359657db919572f4bfcc256a9cc2b6cd9570eb3f983c284ba6f5381362ca5c681d92fc3666180041102393dc4c04
7
- data.tar.gz: eeee4abe91aee56f1df5d9c069512822e313f39fbd7ac7312fdf83be1c966dc1acc52792992727e3a6055a193abd81ec035f31abb44cd66d42e3e86e44cffabf
6
+ metadata.gz: 69afc0f874fe99bcb8c43ba6c42264219484ef59802f6a1daa8ebf84d5b2134b5b3ed29a5570a07358de710d343d3b0b2ff0420d76adc9c5b2987f4e0fc99d84
7
+ data.tar.gz: d63742fbc8b428ca7837a5d9549545d061ea1d0351b89e475be9614c7eb67872247b187e1b777eda93ce16a979905350a54d23fa0032f5f751c7cfe8fc316340
data/.gitignore CHANGED
@@ -25,3 +25,4 @@ test.txt
25
25
  Desktop DB
26
26
  Desktop DF
27
27
 
28
+ .idea
@@ -138,11 +138,16 @@ module Listen
138
138
  loop do
139
139
  break if @stopping
140
140
 
141
- changes = _pop_changes
142
- unless changes.all? { |_,v| v.empty? }
143
- block.call(changes[:modified], changes[:added], changes[:removed])
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
- changes = { modified: [], added: [], removed: [] }
154
- until @changes.empty?
155
- change = @changes.pop
156
- change.each { |k, v| changes[k] << v.to_s }
157
- end
158
- changes.each { |_, v| v.uniq! }
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
@@ -1,3 +1,3 @@
1
1
  module Listen
2
- VERSION = '2.7.0'
2
+ VERSION = '2.7.1'
3
3
  end
@@ -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.01
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.01
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
@@ -1,9 +1,9 @@
1
- def listen
2
- sleep 0.5 # wait for changes
1
+ def listen(lag = 0.5)
2
+ sleep lag # wait for changes
3
3
  sleep_until_next_second
4
4
  reset_changes
5
5
  yield
6
- sleep 0.5 # wait for changes
6
+ sleep lag # wait for changes
7
7
  @changes
8
8
  end
9
9
 
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.0
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-05 00:00:00.000000000 Z
11
+ date: 2014-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid