Skip to content

Commit

Permalink
Adding stream mode.
Browse files Browse the repository at this point in the history
The mode is the first option for the FSEvents::Stream object itself (and not the OSX FSEvent stream). It will primarily affect the strategy for getting an event's modified files.
  • Loading branch information
ymendel committed Jun 30, 2008
1 parent 2dc4f9c commit e4477d5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/fsevents/stream.rb
Expand Up @@ -2,18 +2,23 @@

module FSEvents
class Stream
attr_reader :stream, :last_event
attr_reader :stream, :mode, :last_event
attr_reader :allocator, :context, :paths, :since, :latency, :flags, :callback

class StreamError < StandardError; end

MODES = [:mtime, :cache]

def initialize(*paths, &callback)
raise ArgumentError, 'A callback block is required' if callback.nil?
@callback = callback

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

@mode = options[:mode] || :mtime
raise ArgumentError, "Mode '#{mode}' unknown" unless MODES.include?(@mode)

paths = Dir.pwd if paths.empty?

@allocator = options[:allocator] || OSX::KCFAllocatorDefault
Expand Down
14 changes: 14 additions & 0 deletions spec/stream_spec.rb
Expand Up @@ -50,6 +50,7 @@
[:allocator, :context, :since, :latency, :flags].each do |opt|
@options[opt] = stub(opt.to_s)
end
@options[:mode] = :cache
@other_path = '/other/path'
end

Expand Down Expand Up @@ -113,6 +114,19 @@
@options.delete(:flags)
FSEvents::Stream.new(@path, @options) {}.flags.should == 0
end

it 'should store mode' do
FSEvents::Stream.new(@path, @options) {}.mode.should == @options[:mode]
end

it 'should default mode to mtime' do
@options.delete(:mode)
FSEvents::Stream.new(@path, @options) {}.mode.should == :mtime
end

it 'should not accept any mode other than mtime or cache' do
lambda { FSEvents::Stream.new(@path, @options.merge(:mode => :something_else)) {} }.should raise_error(ArgumentError)
end
end
end

Expand Down

0 comments on commit e4477d5

Please sign in to comment.