From 6ec03cfc05dbc6b0602924a3ce868de66812b705 Mon Sep 17 00:00:00 2001 From: Ben Hoskings Date: Sun, 5 Feb 2012 13:55:31 +1100 Subject: [PATCH] Accept #watch-style arguments when creating a new FSEvent. --- lib/rb-fsevent/fsevent.rb | 4 ++++ spec/rb-fsevent/fsevent_spec.rb | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/rb-fsevent/fsevent.rb b/lib/rb-fsevent/fsevent.rb index c4444e1..c8a2f89 100644 --- a/lib/rb-fsevent/fsevent.rb +++ b/lib/rb-fsevent/fsevent.rb @@ -14,6 +14,10 @@ def watcher_path attr_reader :paths, :callback + def initialize args = nil, &block + watch(args, &block) unless args.nil? + end + def watch(watch_paths, options=nil, &block) @paths = watch_paths.kind_of?(Array) ? watch_paths : [watch_paths] @callback = block diff --git a/spec/rb-fsevent/fsevent_spec.rb b/spec/rb-fsevent/fsevent_spec.rb index e3eb0b5..2ca29c8 100644 --- a/spec/rb-fsevent/fsevent_spec.rb +++ b/spec/rb-fsevent/fsevent_spec.rb @@ -10,6 +10,19 @@ end end + it "shouldn't pass anything to watch when instantiated without a path" do + fsevent = FSEvent.new + fsevent.paths.should be_nil + fsevent.callback.should be_nil + end + + it "should pass path and block to watch when instantiated with them" do + blk = proc { } + fsevent = FSEvent.new(@fixture_path, &blk) + fsevent.paths.should == [@fixture_path] + fsevent.callback.should == blk + end + it "should have a watcher_path that resolves to an executable file" do File.exists?(FSEvent.watcher_path).should be_true File.executable?(FSEvent.watcher_path).should be_true