Skip to content

Commit

Permalink
Letting stream initialization accept multiple paths (not as an array).
Browse files Browse the repository at this point in the history
  • Loading branch information
ymendel committed Jun 13, 2008
1 parent d84b658 commit 1d62afd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/fsevents/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion spec/stream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1d62afd

Please sign in to comment.