fsevents 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ == 0.1.1 2008-07-02
2
+
3
+ * 1 tiny enhancement:
4
+ * Added ability to get deleted files from an Event (or the entire events array) provided the stream is in cache mode.
5
+
1
6
  == 0.1.0 2008-06-30
2
7
 
3
8
  * 1 minor enhancement:
@@ -29,5 +29,16 @@ module FSEvents
29
29
  end
30
30
  end
31
31
  end
32
+
33
+ def deleted_files
34
+ case stream.mode
35
+ when :mtime
36
+ raise RuntimeError, 'This mode does not support getting deleted files'
37
+ when :cache
38
+ cache = stream.dirs[path] || {}
39
+
40
+ cache.keys - files
41
+ end
42
+ end
32
43
  end
33
44
  end
@@ -6,4 +6,8 @@ module EventArray
6
6
  def modified_files
7
7
  collect { |x| x.modified_files }.flatten
8
8
  end
9
+
10
+ def deleted_files
11
+ collect { |x| x.deleted_files }.flatten
12
+ end
9
13
  end
@@ -2,7 +2,7 @@ module Fsevents #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -39,4 +39,21 @@ describe EventArray do
39
39
  @event_array.modified_files.should == files
40
40
  end
41
41
  end
42
+
43
+ it 'should return deleted files' do
44
+ @event_array.should respond_to(:deleted_files)
45
+ end
46
+
47
+ describe 'returning deleted files' do
48
+ it 'should collect deleted files from its events' do
49
+ events = Array.new(3) { stub('event', :deleted_files => Array.new(3) { stub('file') }) }
50
+ files = []
51
+ events.each do |event|
52
+ @event_array << event
53
+ files += event.deleted_files
54
+ end
55
+
56
+ @event_array.deleted_files.should == files
57
+ end
58
+ end
42
59
  end
@@ -204,4 +204,86 @@ describe FSEvents::Event do
204
204
  end
205
205
  end
206
206
  end
207
+
208
+ it 'should list deleted files' do
209
+ @event.should respond_to(:deleted_files)
210
+ end
211
+
212
+ describe 'listing deleted files' do
213
+ it 'should check the stream mode' do
214
+ @stream.expects(:mode)
215
+ @event.deleted_files
216
+ end
217
+
218
+ describe 'when the stream mode is mtime' do
219
+ before :each do
220
+ @stream.stubs(:mode).returns(:mtime)
221
+ end
222
+
223
+ it 'should error' do
224
+ lambda { @event.deleted_files }.should raise_error(RuntimeError)
225
+ end
226
+ end
227
+
228
+ describe 'when the stream mode is cache' do
229
+ before :each do
230
+ @stream.stubs(:mode).returns(:cache)
231
+ end
232
+
233
+ before :each do
234
+ @now = Time.now
235
+ @files = Array.new(5) { |i| stub("file #{i+1}") }
236
+ @event.stubs(:files).returns(@files)
237
+
238
+ @dir_cache = { @path => {} }
239
+ @files.each_with_index do |file, i|
240
+ size = 50 * (i + 1)
241
+ mtime = @now + i - 2
242
+ stat = stub("file #{i+1} stat", :mtime => mtime, :size => size)
243
+ @dir_cache[@path][file] = stat
244
+ end
245
+ @stream.stubs(:dirs).returns(@dir_cache)
246
+ end
247
+
248
+ it 'should get the file list' do
249
+ @event.expects(:files).returns(@files)
250
+ @event.deleted_files
251
+ end
252
+
253
+ it 'should get the stream dir cache' do
254
+ @stream.expects(:dirs).returns(@dir_cache)
255
+ @event.deleted_files
256
+ end
257
+
258
+ it 'should get the dir cache for the event path' do
259
+ sub_cache = @dir_cache[@path]
260
+ @dir_cache.expects(:[]).with(@path).returns(sub_cache)
261
+ @event.deleted_files
262
+ end
263
+
264
+ it 'should return files from the cache that are missing from the file list' do
265
+ expected_files = Array.new(2) { |i| stub("new file #{i+1}") }
266
+ expected_files.each { |file| @dir_cache[@path][file] = stub('stat') }
267
+ deleted_files = @event.deleted_files
268
+
269
+ expected_files.each do |file|
270
+ deleted_files.should include(file)
271
+ end
272
+ end
273
+
274
+ it 'should not return files from that cache that are present in the file list' do
275
+ unexpected_files = @files
276
+ deleted_files = @event.deleted_files
277
+
278
+ unexpected_files.each do |file|
279
+ deleted_files.should_not include(file)
280
+ end
281
+ end
282
+
283
+ it 'should handle this path not yet cached' do
284
+ @dir_cache.delete(@path)
285
+ @event.deleted_files.should == []
286
+ end
287
+ end
288
+ end
207
289
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fsevents
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yossef Mendelssohn
@@ -9,10 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-30 00:00:00 -05:00
12
+ date: 2008-07-02 00:00:00 -05:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.7.0
24
+ version:
16
25
  description: Simple, usable FSEvents API
17
26
  email:
18
27
  - ymendel@pobox.com