callback 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ 2006-11-24 (0.3.0)
2
+ * Added Module#callback method. Also added all of the callback methods into Object.
3
+
1
4
  2006-11-04 (0.2.0)
2
5
  * Added register_callback as an alias to define_callback. Added unregistration of callbacks in the
3
6
  unregister_callback and undefine_callback methods.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/clean'
5
5
  require 'rake/rdoctask'
6
6
 
7
7
  PKG_NAME = "callback"
8
- PKG_VERSION = "0.2.0"
8
+ PKG_VERSION = "0.3.0"
9
9
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
10
10
  PKG_FILES = FileList[
11
11
  '[A-Z]*',
data/lib/callback.rb CHANGED
@@ -1,3 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/callback/callback"
3
- require "#{dir}/callback/callback_container"
1
+ require "callback/callback"
2
+ require "callback/extensions/object"
3
+ require "callback/extensions/module"
4
+ require "callback/callback_container"
@@ -1,21 +1,34 @@
1
1
  module Callback
2
- def define_callback(key, callback_proc=nil, &callback_block)
3
- callbacks.define(key, callback_proc, &callback_block)
2
+ module ModuleMethods
3
+ def callback(event_name)
4
+ module_eval %{
5
+ def on_#{event_name}(&block)
6
+ define_callback(:#{event_name}, &block)
7
+ end
8
+ }
9
+ end
4
10
  end
5
- alias_method :register_callback, :define_callback
6
11
 
7
- def undefine_callback(key, callback_proc)
8
- callbacks.undefine(key, callback_proc)
9
- end
10
- alias_method :unregister_callback, :undefine_callback
12
+ module InstanceMethods
13
+ def define_callback(key, callback_proc=nil, &callback_block)
14
+ callbacks.define(key, callback_proc, &callback_block)
15
+ end
16
+ alias_method :register_callback, :define_callback
11
17
 
12
- protected
13
- def notify_callbacks(key, *args, &error_handler)
14
- callbacks.notify(key, *args, &error_handler)
15
- end
18
+ def undefine_callback(key, callback_proc)
19
+ callbacks.undefine(key, callback_proc)
20
+ end
21
+ alias_method :unregister_callback, :undefine_callback
22
+
23
+ protected
24
+ def notify_callbacks(key, *args, &error_handler)
25
+ callbacks.notify(key, *args, &error_handler)
26
+ end
16
27
 
17
- private
18
- def callbacks
19
- @callbacks ||= CallbackContainer.new
28
+ private
29
+ def callbacks
30
+ @callbacks ||= CallbackContainer.new
31
+ end
20
32
  end
33
+ include InstanceMethods
21
34
  end
@@ -0,0 +1,3 @@
1
+ class Module
2
+ include Callback::ModuleMethods
3
+ end
@@ -0,0 +1,3 @@
1
+ class Object
2
+ include Callback::InstanceMethods
3
+ end
@@ -0,0 +1,19 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/spec_helper"
3
+
4
+ context "A Module" do
5
+ specify "should define callback methods" do
6
+ the_class = Class.new do
7
+ callback :foo
8
+ def call
9
+ notify_callbacks :foo
10
+ end
11
+ end
12
+
13
+ the_obj = the_class.new
14
+ the_obj.on_foo do
15
+ :bar
16
+ end
17
+ the_obj.call.should == [:bar]
18
+ end
19
+ end
@@ -1,10 +1,9 @@
1
1
  dir = File.dirname(__FILE__)
2
2
  require "#{dir}/spec_helper"
3
3
 
4
- context "A Callback" do
4
+ context "An Object" do
5
5
  setup do
6
6
  @callback_object = Object.new
7
- @callback_object.extend Callback
8
7
  class << @callback_object
9
8
  public :notify_callbacks
10
9
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "rubygems"
2
2
  require "spec"
3
3
  dir = File.dirname(__FILE__)
4
- require "#{dir}/../lib/callback"
4
+ $LOAD_PATH << "#{dir}/../lib"
5
+ require "callback"
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: callback
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.0
7
- date: 2006-11-04 00:00:00 -08:00
6
+ version: 0.3.0
7
+ date: 2006-11-24 00:00:00 -08:00
8
8
  summary: A simple callback library for ruby objects.
9
9
  require_paths:
10
10
  - lib
@@ -36,11 +36,15 @@ files:
36
36
  - lib/callback.rb
37
37
  - lib/callback/callback.rb
38
38
  - lib/callback/callback_container.rb
39
- - spec/callback_spec.rb
39
+ - lib/callback/extensions/module.rb
40
+ - lib/callback/extensions/object.rb
41
+ - spec/module_spec.rb
40
42
  - spec/spec_helper.rb
41
43
  - spec/spec_suite.rb
44
+ - spec/object_spec.rb
42
45
  test_files:
43
- - spec/callback_spec.rb
46
+ - spec/module_spec.rb
47
+ - spec/object_spec.rb
44
48
  rdoc_options: []
45
49
 
46
50
  extra_rdoc_files: