From 1d62afd534abe49a9f47c4579924e12616848106 Mon Sep 17 00:00:00 2001 From: Yossef Mendelssohn Date: Fri, 13 Jun 2008 16:00:00 -0500 Subject: [PATCH] Letting stream initialization accept multiple paths (not as an array). --- lib/fsevents/stream.rb | 9 +++++++-- spec/stream_spec.rb | 22 +++++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/fsevents/stream.rb b/lib/fsevents/stream.rb index 596d763..9afd731 100644 --- a/lib/fsevents/stream.rb +++ b/lib/fsevents/stream.rb @@ -4,11 +4,16 @@ class Stream class StreamError < StandardError; end - def initialize(paths, options = {}) + def initialize(*paths) + options = {} + options = paths.pop if paths.last.is_a?(Hash) + + raise ArgumentError, "path required" if paths.empty? + allocator = options[:allocator] || OSX::KCFAllocatorDefault callback = options[:callback] context = options[:context] || nil - paths = [*paths] + paths = [*paths].flatten since = options[:since] || OSX::KFSEventStreamEventIdSinceNow latency = options[:latency] || 1.0 flags = options[:flags ] || 0 diff --git a/spec/stream_spec.rb b/spec/stream_spec.rb index b345745..853537e 100644 --- a/spec/stream_spec.rb +++ b/spec/stream_spec.rb @@ -25,13 +25,25 @@ end it 'should accept a hash of options' do - lambda { FSEvents::Stream.new(@path, { :flags => 27 }) }.should_not raise_error(ArgumentError) + 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 accept an array of paths with options' do + lambda { FSEvents::Stream.new([@path, '/other/path'], :flags => 27) }.should_not raise_error + end + + it 'should accept multiple paths' do + lambda { FSEvents::Stream.new(@path, '/other/path') }.should_not raise_error + end + + it 'should accept multiple paths with options' do + lambda { FSEvents::Stream.new(@path, '/other/path', :flags => 27) }.should_not raise_error + end + it 'should create a new stream' do OSX.expects(:FSEventStreamCreate).returns(@stream) FSEvents::Stream.new(@path) @@ -86,6 +98,14 @@ FSEvents::Stream.new([@path, other_path], @options) end + it 'should make an array of the paths if given multiple 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