callback 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ 2006-11-25 (0.4.0)
2
+ * Module.callback adds notify_event_name method
3
+ * Allow multiple callbacks to be defined with the Module.callback method
4
+
1
5
  2006-11-25 (0.3.2)
2
6
  * Added CallbackContainer#clear method
3
7
 
data/Rakefile CHANGED
@@ -5,13 +5,14 @@ require 'rake/clean'
5
5
  require 'rake/rdoctask'
6
6
 
7
7
  PKG_NAME = "callback"
8
- PKG_VERSION = "0.3.2"
8
+ PKG_VERSION = "0.4.0"
9
9
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
10
10
  PKG_FILES = FileList[
11
11
  '[A-Z]*',
12
12
  '*.rb',
13
13
  'lib/**/*.rb',
14
- 'spec/**/*.rb'
14
+ 'spec/**/*.rb',
15
+ 'examples/**/*.rb'
15
16
  ]
16
17
 
17
18
  spec = Gem::Specification.new do |s|
@@ -40,3 +41,10 @@ Rake::GemPackageTask.new(spec) do |pkg|
40
41
  pkg.need_zip = true
41
42
  pkg.need_tar = true
42
43
  end
44
+
45
+ desc "Run all of the specs"
46
+ task :spec do
47
+ ARGV << "--format"
48
+ ARGV << "specdoc"
49
+ require "spec/spec_suite"
50
+ end
@@ -0,0 +1,18 @@
1
+ require "rubygems"
2
+ require "callback"
3
+
4
+ class Foo
5
+ callback :bar, :baz
6
+
7
+ def notify_all_callbacks
8
+ raise "Bar callback not correct" unless notify_bar == [1]
9
+ raise "Baz callback not correct" unless notify_baz == [2]
10
+ puts "Callbacks seem to be working"
11
+ end
12
+ end
13
+
14
+ f = Foo.new
15
+
16
+ f.bar {1}
17
+ f.baz {2}
18
+ f.notify_all_callbacks
@@ -1,11 +1,19 @@
1
1
  module Callback
2
2
  module ModuleMethods
3
- def callback(event_name)
4
- module_eval %{
5
- def #{event_name}(&block)
6
- define_callback(:#{event_name}, &block)
7
- end
8
- }
3
+ def callback(*event_names)
4
+ event_names.each do |event_name|
5
+ module_eval %{
6
+ def #{event_name}(&block)
7
+ define_callback(:#{event_name}, &block)
8
+ end
9
+
10
+ def notify_#{event_name}(*args, &error_handler)
11
+ notify_callbacks(:#{event_name}, *args, &error_handler)
12
+ end
13
+ }
14
+
15
+ protected :"notify_#{event_name}"
16
+ end
9
17
  end
10
18
  end
11
19
 
@@ -2,18 +2,25 @@ dir = File.dirname(__FILE__)
2
2
  require "#{dir}/spec_helper"
3
3
 
4
4
  context "A Module" do
5
- specify "should define callback methods" do
5
+ specify "should define callback and notify callback methods" do
6
6
  the_class = Class.new do
7
7
  callback :foo
8
- def call
9
- notify_callbacks :foo
10
- end
11
8
  end
12
9
 
13
10
  the_obj = the_class.new
14
- the_obj.foo do
15
- :bar
11
+ the_obj.foo { :bar }
12
+ the_obj.send(:notify_foo).should == [:bar]
13
+ end
14
+
15
+ specify "should define multiple callbacks" do
16
+ the_class = Class.new do
17
+ callback :foo, :bar
16
18
  end
17
- the_obj.call.should == [:bar]
19
+
20
+ the_obj = the_class.new
21
+ the_obj.foo { 1 }
22
+ the_obj.bar { 2 }
23
+ the_obj.send(:notify_foo).should == [1]
24
+ the_obj.send(:notify_bar).should == [2]
18
25
  end
19
26
  end
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: callback
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.2
6
+ version: 0.4.0
7
7
  date: 2006-11-25 00:00:00 -08:00
8
8
  summary: A simple callback library for ruby objects.
9
9
  require_paths:
@@ -43,6 +43,7 @@ files:
43
43
  - spec/spec_suite.rb
44
44
  - spec/callback_container_spec.rb
45
45
  - spec/object_spec.rb
46
+ - examples/callback_example.rb
46
47
  test_files:
47
48
  - spec/module_spec.rb
48
49
  - spec/callback_container_spec.rb