Permalink
Browse files

Support :all.

  • Loading branch information...
1 parent fab64a2 commit f6390faa1b356c47d734d831a77306288e3d2a5a @jbarnette committed Mar 8, 2012
Showing with 25 additions and 0 deletions.
  1. +19 −0 README.markdown
  2. +1 −0 lib/watchable.rb
  3. +5 −0 test/watchable_test.rb
View
@@ -58,6 +58,25 @@ frob.fire :twiddle, "John"
(not that there's anything wrong with that)
{ :called! => ["John"] }
+### Watching Everything
+
+Want to see every event? Register for `:all`. The first argument will
+be the name of the fired event.
+
+```ruby
+frob = Frob.new
+
+frob.on :all do |event, culprit|
+ p :fired => [event, culprit]
+end
+
+frob.fire :foo, "John"
+```
+
+#### Result
+
+ {:fired => [:foo, "John"]}
+
### Watching Once
Only want to be notified the first time something happens? `once` is
View
@@ -5,6 +5,7 @@ def watchers
def fire event, *args
watchers[event].each { |w| w && w.call(*args) }
+ watchers[:all].each { |w| w && w.call(event, *args) }
self
end
View
@@ -90,6 +90,11 @@
assert_equal [b], @obj.watchers[:foo]
end
+ it "can register for all events" do
+ @obj.on :all, mock { expects(:call).with :foo, :bar }
+ @obj.fire :foo, :bar
+ end
+
it "returns the watchable" do
assert_same @obj, @obj.on(:foo) {}
end

0 comments on commit f6390fa

Please sign in to comment.