Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Modernize the project -- get rid of Hoe, use Bundler and RSpec.

  • Loading branch information...
commit ef009bed7d9f000d47f807c3e7a209cb7e31d882 1 parent c5a385a
@jcoglan authored
View
6 .gitignore
@@ -1,3 +1,3 @@
-doc
-pkg
-README.txt
+Gemfile.lock
+*.gem
+
View
3  Gemfile
@@ -0,0 +1,3 @@
+source :rubygems
+gemspec
+
View
6 Manifest.txt
@@ -1,6 +0,0 @@
-History.txt
-Manifest.txt
-README.txt
-Rakefile
-lib/eventful.rb
-test/test_eventful.rb
View
79 README.rdoc
@@ -1,18 +1,10 @@
= Eventful
-* http://github.com/jcoglan/eventful
-
+Eventful+ is a small extension on top of Ruby's +Observable+ module that
-implements named events, block listeners and event bubbling. It allows
-much more flexible event handling behaviour than is typically allowed
-by +Observable+, which requires listeners to be objects that implement
-+update+ and provides no simple way of calling subsets of observers based
-on event type.
-
-
-== Installation
-
- sudo gem install eventful
+implements named events, block listeners and event bubbling. It allows much
+more flexible event handling behaviour than is typically allowed by
++Observable+, which requires listeners to be objects that implement +update+
+and provides no simple way of calling subsets of observers based on event type.
== Examples
@@ -23,10 +15,9 @@ Make a class listenable by mixing +Eventful+ into it:
include Eventful
end
-Register event listeners using +on+ with an event name and a block.
-Publish events using +fire+ with the event name. The block accepts
-the object that published the event, along with any parameters passed
-to +fire+.
+Register event listeners using +on+ with an event name and a block. Publish
+events using +fire+ with the event name. The block accepts the object that
+published the event, along with any parameters passed to +fire+.
w = Watcher.new
@@ -51,8 +42,8 @@ so you can remove it using +delete_observer+.
=== Method chains instead of blocks
-Instead of passing a block, you can add behaviour to objects by chaining
-method calls after the +on+ call. For example:
+Instead of passing a block, you can add behaviour to objects by chaining method
+calls after the +on+ call. For example:
class Logger
include Eventful
@@ -71,10 +62,10 @@ method calls after the +on+ call. For example:
=== Events that bubble
-When you +fire+ an event, the event 'bubbles' up the type system. What
-this means is that you can listen to events on all the instances of a
-class just by placing an event listener on the class itself. As above,
-the listener is called with the instance that fired the event.
+When you +fire+ an event, the event 'bubbles' up the type system. What this
+means is that you can listen to events on all the instances of a class just by
+placing an event listener on the class itself. As above, the listener is called
+with the instance that fired the event.
Logger.on(:receive) { |log, msg| puts "#{ log } :: #{ msg }" }
@@ -87,8 +78,8 @@ the listener is called with the instance that fired the event.
# #<Logger:0xb7bf103c> :: The first message
# #<Logger:0xb7bf1028> :: Another event
-Method chains can also be used, and they will be replayed on the instance
-that initiated the event.
+Method chains can also be used, and they will be replayed on the instance that
+initiated the event.
# Calls `log.print "Received message"`
@@ -102,23 +93,23 @@ that initiated the event.
(The MIT License)
-Copyright (c) 2009 James Coglan
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-'Software'), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+Copyright (c) 2009-2012 James Coglan
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the 'Software'), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
View
12 Rakefile
@@ -1,12 +0,0 @@
-# -*- ruby -*-
-
-require 'rubygems'
-require 'hoe'
-
-Hoe.spec 'eventful' do |p|
- # self.rubyforge_name = 'eventfulx' # if different than 'eventful'
- p.developer('James Coglan', 'jcoglan@googlemail.com')
- p.extra_deps = %w[methodphitamine]
-end
-
-# vim: syntax=ruby
View
18 eventful.gemspec
@@ -0,0 +1,18 @@
+Gem::Specification.new do |s|
+ s.name = "eventful"
+ s.version = "1.0.1"
+ s.summary = "A little pub/sub abstraction based on Observable"
+ s.author = "James Coglan"
+ s.email = "jcoglan@gmail.com"
+ s.homepage = "http://github.com/jcoglan/eventful"
+
+ s.extra_rdoc_files = %w[README.rdoc]
+ s.rdoc_options = %w[--main README.rdoc]
+ s.require_paths = %w[lib]
+
+ s.files = %w[README.rdoc History.txt] + Dir.glob("{lib,spec}/**/*.rb")
+
+ s.add_dependency "methodphitamine", "= 1.0.0"
+ s.add_development_dependency "rspec"
+end
+
View
1  lib/eventful.rb
@@ -1,5 +1,4 @@
require 'observer'
-require 'rubygems'
require 'methodphitamine'
# Adds named event publishing capabilities to the class that includes it.
View
46 test/test_eventful.rb → spec/eventful_spec.rb
@@ -1,6 +1,4 @@
-require "test/unit"
-require "eventful"
-require "set"
+require "spec_helper"
class Foo
include Eventful
@@ -19,31 +17,31 @@ class Bar
include Eventful
end
-class TestEventful < Test::Unit::TestCase
- def setup
+describe Eventful do
+ before do
[Foo, Bar, Eventful].each &it.delete_observers
end
- def test_named_events
+ it "fires events" do
ayes, noes = 0, 0
f = Foo.new
f.on(:aye) { |foo, x| ayes += x }
obs = f.on(:noe) { |foo, x| noes += x }
f.fire(:aye, 1)
- assert_equal 1, ayes
- assert_equal 0, noes
+ ayes.should == 1
+ noes.should == 0
f.fire(:noe, 3)
- assert_equal 1, ayes
- assert_equal 3, noes
+ ayes.should == 1
+ noes.should == 3
f.delete_observer(obs)
f.fire(:noe, 3)
- assert_equal 1, ayes
- assert_equal 3, noes
+ ayes.should == 1
+ noes.should == 3
end
- def test_chaining
+ it "allows chaining" do
f = Foo.new
f.on(:aye).bump! 2
f.on(:noe).bump! -1
@@ -51,10 +49,10 @@ def test_chaining
2.times { f.fire(:aye) }
f.fire(:noe)
- assert_equal 3, f.count
+ f.count.should == 3
end
- def test_bubbling
+ it "bubbles events" do
bar1, bar2 = Bar.new, Bar.new
list = []
Bar.on(:aye) { |r| list << r }
@@ -62,24 +60,24 @@ def test_bubbling
Eventful.on(:noe) { |r| list << r }
bar1.fire(:aye)
- assert_equal [bar1, bar1], list
+ list.should == [bar1, bar1]
bar2.fire(:noe)
- assert_equal [bar1, bar1, bar2], list
+ list.should == [bar1, bar1, bar2]
Bar.fire(:aye)
- assert_equal [bar1, bar1, bar2, Bar], list
+ list.should == [bar1, bar1, bar2, Bar]
Bar.fire(:noe)
- assert_equal [bar1, bar1, bar2, Bar], list
+ list.should == [bar1, bar1, bar2, Bar]
end
- def test_chaining_on_bubble
+ it "allows chaining on bubble" do
f1, f2 = Foo.new, Foo.new
Foo.on(:aye).bump! 5
f1.fire(:aye)
- assert_equal 5, f1.count
- assert_equal 0, f2.count
+ f1.count.should == 5
+ f2.count.should == 0
f2.fire(:aye)
- assert_equal 5, f1.count
- assert_equal 5, f2.count
+ f1.count.should == 5
+ f2.count.should == 5
end
end
View
4 spec/spec_helper.rb
@@ -0,0 +1,4 @@
+require 'rubygems'
+require 'bundler/setup'
+require File.expand_path('../../lib/eventful', __FILE__)
+
Please sign in to comment.
Something went wrong with that request. Please try again.