Skip to content

Commit

Permalink
FSEvents::Event#modified_files -- uses the stream last event time to …
Browse files Browse the repository at this point in the history
…get modified files in the event path.
  • Loading branch information
ymendel committed Jun 15, 2008
1 parent 68ca385 commit 167e74b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/fsevents/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ def initialize(id, path, stream)
def files
Dir["#{path}/*"]
end

def modified_files
files.select { |f| File.mtime(f) >= stream.last_event }
end
end
end
end
56 changes: 55 additions & 1 deletion spec/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,59 @@
it 'should get files from the path' do
@event.files.sort.should == Dir["#{@path}/*"].sort
end
end
end

it 'should list modified files' do
@event.should respond_to(:modified_files)
end

describe 'listing modified files' do
before :each do
@now = Time.now
@stream.stubs(:last_event).returns(@now)
@files = Array.new(5) do |i|
file = stub("file #{i+1}")
File.stubs(:mtime).with(file).returns(@now + i - 2)
file
end
@event.stubs(:files).returns(@files)
end

it 'should get the file list' do
@event.expects(:files).returns(@files)
@event.modified_files
end

it 'should get the last event time from the stream' do
@stream.expects(:last_event).returns(@now)
@event.modified_files
end

it 'should return files modified after the last event time' do
expected_files = @files.values_at(3, 4)
modified_files = @event.modified_files

expected_files.each do |file|
modified_files.should include(file)
end
end

it 'should return files modified at the last event time' do
expected_files = @files.values_at(2)
modified_files = @event.modified_files

expected_files.each do |file|
modified_files.should include(file)
end
end

it 'should not return files not modified after the last event time' do
unexpected_files = @files.values_at(0, 1)
modified_files = @event.modified_files

unexpected_files.each do |file|
modified_files.should_not include(file)
end
end
end
end

0 comments on commit 167e74b

Please sign in to comment.