hookr 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/lib/hookr.rb +21 -6
- data/spec/hookr_spec.rb +1 -1
- data/version.txt +1 -0
- metadata +17 -7
data/History.txt
CHANGED
data/lib/hookr.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
require 'set'
|
2
|
-
|
2
|
+
|
3
|
+
if '1.9'.respond_to?(:force_encoding)
|
4
|
+
require 'enumerator'
|
5
|
+
MyEnumerator = Enumerator
|
6
|
+
else
|
7
|
+
require 'generator'
|
8
|
+
MyEnumerator = Generator
|
9
|
+
end
|
3
10
|
require 'rubygems'
|
4
11
|
require 'fail_fast'
|
5
12
|
|
@@ -254,14 +261,14 @@ module HookR
|
|
254
261
|
fetch_or_create_hooks[hook_name].execute_callbacks(event)
|
255
262
|
end
|
256
263
|
|
257
|
-
# Returns a
|
264
|
+
# Returns a Enumerator which yields:
|
258
265
|
# 1. Wildcard callbacks, in reverse order, followed by
|
259
266
|
# 2. +hook_name+ callbacks, in reverse order, followed by
|
260
267
|
# 3. a proc which delegates to +block+
|
261
268
|
#
|
262
269
|
# Intended for use with recursive hook execution.
|
263
270
|
def callback_generator(hook_name, block)
|
264
|
-
|
271
|
+
MyEnumerator.new do |g|
|
265
272
|
fetch_or_create_hooks[:__wildcard__].each_callback_reverse do |callback|
|
266
273
|
g.yield callback
|
267
274
|
end
|
@@ -508,6 +515,14 @@ module HookR
|
|
508
515
|
end
|
509
516
|
end
|
510
517
|
|
518
|
+
def to_a
|
519
|
+
if frozen? && !@keys
|
520
|
+
@hash.keys.sort
|
521
|
+
else
|
522
|
+
super
|
523
|
+
end
|
524
|
+
end
|
525
|
+
|
511
526
|
# get the first callback
|
512
527
|
def first
|
513
528
|
each do |cb|
|
@@ -521,7 +536,7 @@ module HookR
|
|
521
536
|
|
522
537
|
end
|
523
538
|
|
524
|
-
Callback
|
539
|
+
class Callback < Struct.new(:handle, :index)
|
525
540
|
include Comparable
|
526
541
|
include FailFast::Assertions
|
527
542
|
|
@@ -646,8 +661,8 @@ module HookR
|
|
646
661
|
assert(recursive, callbacks)
|
647
662
|
event = self.class.new(source, name, arguments, recursive, callbacks)
|
648
663
|
event.arguments = args unless args.empty?
|
649
|
-
if callbacks.next
|
650
|
-
|
664
|
+
if c = callbacks.next
|
665
|
+
c.call(event)
|
651
666
|
else
|
652
667
|
raise "No more callbacks!"
|
653
668
|
end
|
data/spec/hookr_spec.rb
CHANGED
@@ -173,7 +173,7 @@ describe HookR::Hooks do
|
|
173
173
|
|
174
174
|
it "should define a Listener class responding to #foo and #bar" do
|
175
175
|
@listener_class = @class::Listener
|
176
|
-
@listener_class.instance_methods(false).should include("foo", "bar")
|
176
|
+
@listener_class.instance_methods(false).map(&:to_s).should include("foo", "bar")
|
177
177
|
end
|
178
178
|
|
179
179
|
describe "given a subscribed Listener" do
|
data/version.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.1.1
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hookr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 1
|
7
8
|
- 1
|
8
|
-
-
|
9
|
-
version: 1.1.
|
9
|
+
- 1
|
10
|
+
version: 1.1.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Avdi Grimm
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
+
date: 2011-07-06 00:00:00 -04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: fail-fast
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
|
-
- - "
|
27
|
+
- - "="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 23
|
27
30
|
segments:
|
28
31
|
- 1
|
29
32
|
- 0
|
@@ -35,14 +38,16 @@ dependencies:
|
|
35
38
|
name: bones
|
36
39
|
prerelease: false
|
37
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
38
42
|
requirements:
|
39
43
|
- - ">="
|
40
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 27
|
41
46
|
segments:
|
42
47
|
- 3
|
43
|
-
- 4
|
44
48
|
- 7
|
45
|
-
|
49
|
+
- 0
|
50
|
+
version: 3.7.0
|
46
51
|
type: :development
|
47
52
|
version_requirements: *id002
|
48
53
|
description: HookR is a publish/subscribe callback hook facility for Ruby.
|
@@ -67,6 +72,7 @@ files:
|
|
67
72
|
- spec/hookr_spec.rb
|
68
73
|
- spec/spec_helper.rb
|
69
74
|
- test/test_hookr.rb
|
75
|
+
- version.txt
|
70
76
|
has_rdoc: true
|
71
77
|
homepage: http://hookr.rubyforge.org
|
72
78
|
licenses: []
|
@@ -78,23 +84,27 @@ rdoc_options:
|
|
78
84
|
require_paths:
|
79
85
|
- lib
|
80
86
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
81
88
|
requirements:
|
82
89
|
- - ">="
|
83
90
|
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
84
92
|
segments:
|
85
93
|
- 0
|
86
94
|
version: "0"
|
87
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
88
97
|
requirements:
|
89
98
|
- - ">="
|
90
99
|
- !ruby/object:Gem::Version
|
100
|
+
hash: 3
|
91
101
|
segments:
|
92
102
|
- 0
|
93
103
|
version: "0"
|
94
104
|
requirements: []
|
95
105
|
|
96
106
|
rubyforge_project: hookr
|
97
|
-
rubygems_version: 1.3.
|
107
|
+
rubygems_version: 1.3.7
|
98
108
|
signing_key:
|
99
109
|
specification_version: 3
|
100
110
|
summary: A callback hooks framework for Ruby.
|