Skip to content

Commit

Permalink
Letting stream initialization accept a path or multiple paths (as an …
Browse files Browse the repository at this point in the history
…array).
  • Loading branch information
ymendel committed Jun 13, 2008
1 parent 761dba4 commit d84b658
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/fsevents/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions spec/stream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d84b658

Please sign in to comment.