From d84b658abf2280653a412a59c58456efa43b52a4 Mon Sep 17 00:00:00 2001 From: Yossef Mendelssohn Date: Fri, 13 Jun 2008 15:50:38 -0500 Subject: [PATCH] Letting stream initialization accept a path or multiple paths (as an array). --- lib/fsevents/stream.rb | 6 +++--- spec/stream_spec.rb | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/fsevents/stream.rb b/lib/fsevents/stream.rb index 19ac837..596d763 100644 --- a/lib/fsevents/stream.rb +++ b/lib/fsevents/stream.rb @@ -4,16 +4,16 @@ class Stream class StreamError < StandardError; end - def initialize(path, options = {}) + def initialize(paths, options = {}) allocator = options[:allocator] || OSX::KCFAllocatorDefault callback = options[:callback] context = options[:context] || nil - path = [path] + paths = [*paths] since = options[:since] || OSX::KFSEventStreamEventIdSinceNow latency = options[:latency] || 1.0 flags = options[:flags ] || 0 - @stream = OSX.FSEventStreamCreate(allocator, callback, context, path, since, latency, flags) + @stream = OSX.FSEventStreamCreate(allocator, callback, context, paths, since, latency, flags) raise StreamError, 'Unable to create FSEvents stream.' unless @stream end diff --git a/spec/stream_spec.rb b/spec/stream_spec.rb index 2b8bc71..b345745 100644 --- a/spec/stream_spec.rb +++ b/spec/stream_spec.rb @@ -28,6 +28,10 @@ lambda { FSEvents::Stream.new(@path, { :flags => 27 }) }.should_not raise_error(ArgumentError) end + it 'should accept an array of paths' do + lambda { FSEvents::Stream.new([@path, '/other/path']) }.should_not raise_error + end + it 'should create a new stream' do OSX.expects(:FSEventStreamCreate).returns(@stream) FSEvents::Stream.new(@path) @@ -74,6 +78,14 @@ FSEvents::Stream.new(@path, @options) end + it 'should pass the paths as-is if given an array of paths' do + other_path = '/other/path' + args = @arg_placeholders + args[3] = [@path, other_path] + OSX.expects(:FSEventStreamCreate).with(*args).returns(@stream) + FSEvents::Stream.new([@path, other_path], @options) + end + it 'should pass the since (event ID)' do args = @arg_placeholders args[4] = @since