From 6d6e3d9c9860a3b4623c807edd3372f27bf8f189 Mon Sep 17 00:00:00 2001 From: Yossef Mendelssohn Date: Mon, 30 Jun 2008 01:46:01 -0500 Subject: [PATCH] Stripping trailing slash from paths. This was originally just a minor visual annoyance, but it became something that messed up the caching. --- lib/fsevents/event.rb | 2 +- lib/fsevents/stream.rb | 3 ++- spec/event_spec.rb | 4 ++++ spec/stream_spec.rb | 4 ++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/fsevents/event.rb b/lib/fsevents/event.rb index 53ce944..c640ac7 100644 --- a/lib/fsevents/event.rb +++ b/lib/fsevents/event.rb @@ -4,7 +4,7 @@ class Event def initialize(id, path, stream) @id = id - @path = path + @path = path.sub(%r%/$%, '') @stream = stream end diff --git a/lib/fsevents/stream.rb b/lib/fsevents/stream.rb index df145ca..ba14514 100644 --- a/lib/fsevents/stream.rb +++ b/lib/fsevents/stream.rb @@ -21,10 +21,11 @@ def initialize(*paths, &callback) @dirs = {} paths = Dir.pwd if paths.empty? + paths = [paths].flatten.collect { |path| path.sub(%r%/$%, '') } @allocator = options[:allocator] || OSX::KCFAllocatorDefault @context = options[:context] || nil - @paths = [paths].flatten + @paths = paths @since = options[:since] || OSX::KFSEventStreamEventIdSinceNow @latency = options[:latency] || 1.0 @flags = options[:flags] || 0 diff --git a/spec/event_spec.rb b/spec/event_spec.rb index 67ab3d1..6376355 100644 --- a/spec/event_spec.rb +++ b/spec/event_spec.rb @@ -34,6 +34,10 @@ FSEvents::Event.new(@id, @path, @stream).path.should == @path end + it 'should strip a trailing / from the path' do + FSEvents::Event.new(@id, "#{@path}/", @stream).path.should == @path + end + it 'should store the stream' do FSEvents::Event.new(@id, @path, @stream).stream.should == @stream end diff --git a/spec/stream_spec.rb b/spec/stream_spec.rb index 5016fcc..a831534 100644 --- a/spec/stream_spec.rb +++ b/spec/stream_spec.rb @@ -88,6 +88,10 @@ FSEvents::Stream.new(@options) {}.paths.should == [Dir.pwd] end + it 'should strip a trailing slash from the path' do + FSEvents::Stream.new("#{@path}/", "#{@other_path}/", @options) {}.paths.should == [@path, @other_path] + end + it "should store 'since' (event ID)" do FSEvents::Stream.new(@path, @options) {}.since.should == @options[:since] end