callback 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +3 -0
- data/Rakefile +1 -1
- data/lib/callback.rb +4 -3
- data/lib/callback/callback.rb +27 -14
- data/lib/callback/extensions/module.rb +3 -0
- data/lib/callback/extensions/object.rb +3 -0
- data/spec/module_spec.rb +19 -0
- data/spec/{callback_spec.rb → object_spec.rb} +1 -2
- data/spec/spec_helper.rb +2 -1
- metadata +8 -4
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
data/lib/callback.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
-
|
2
|
-
require "
|
3
|
-
require "
|
1
|
+
require "callback/callback"
|
2
|
+
require "callback/extensions/object"
|
3
|
+
require "callback/extensions/module"
|
4
|
+
require "callback/callback_container"
|
data/lib/callback/callback.rb
CHANGED
@@ -1,21 +1,34 @@
|
|
1
1
|
module Callback
|
2
|
-
|
3
|
-
|
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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
28
|
+
private
|
29
|
+
def callbacks
|
30
|
+
@callbacks ||= CallbackContainer.new
|
31
|
+
end
|
20
32
|
end
|
33
|
+
include InstanceMethods
|
21
34
|
end
|
data/spec/module_spec.rb
ADDED
@@ -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
|
data/spec/spec_helper.rb
CHANGED
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.
|
7
|
-
date: 2006-11-
|
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
|
-
-
|
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/
|
46
|
+
- spec/module_spec.rb
|
47
|
+
- spec/object_spec.rb
|
44
48
|
rdoc_options: []
|
45
49
|
|
46
50
|
extra_rdoc_files:
|