Skip to content

Commit

Permalink
Continuing initialization refactoring, storing callback block.
Browse files Browse the repository at this point in the history
Note that the callback here is the 'real' callback, the one the user is interested in. The FSEvent stream callback will be the same boring thing every time.
  • Loading branch information
ymendel committed Jun 14, 2008
1 parent eed34f7 commit 1dacda4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/fsevents/stream.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
module FSEvents
class Stream
attr_reader :stream
attr_reader :allocator, :context, :paths, :since, :latency, :flags
attr_reader :allocator, :context, :paths, :since, :latency, :flags, :callback

class StreamError < StandardError; end

def initialize(*paths)
def initialize(*paths, &callback)
@callback = callback

options = {}
options = paths.pop if paths.last.is_a?(Hash)

Expand Down
15 changes: 12 additions & 3 deletions spec/stream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
OSX.stubs(:FSEventStreamCreate).returns(@stream)
end

it 'should accept a path' do
lambda { FSEvents::Stream.new(@path) }.should_not raise_error(ArgumentError)
it 'should accept a path and callback block' do
lambda { FSEvents::Stream.new(@path) {} }.should_not raise_error(ArgumentError)
end

it 'should not require a path' do
lambda { FSEvents::Stream.new }.should_not raise_error(ArgumentError)
lambda { FSEvents::Stream.new() {} }.should_not raise_error(ArgumentError)
end

it 'should not require a callback block' do
lambda { FSEvents::Stream.new(@path) }.should_not raise_error(ArgumentError)
end

it 'should accept a hash of options' do
Expand All @@ -44,6 +48,11 @@
lambda { FSEvents::Stream.new(@path, '/other/path', :flags => 27) }.should_not raise_error
end

it 'should store the callback block' do
callback = lambda {}
FSEvents::Stream.new(@path, &callback).callback.should == callback
end

describe 'handling options' do
before :each do
@options = {}
Expand Down

0 comments on commit 1dacda4

Please sign in to comment.