eventer 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +4 -0
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/README.en.md +25 -2
- data/README.md +25 -3
- data/lib/eventer.rb +17 -10
- data/lib/eventer/version.rb +1 -1
- data/spec/eventer_spec.rb +91 -1
- metadata +9 -7
- data/Gemfile.lock +0 -27
data/.document
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/README.en.md
CHANGED
@@ -28,8 +28,31 @@ Also, there is the procedure allowing to output the simple result value as an Ar
|
|
28
28
|
|
29
29
|
t.event_rs :event, args... # -> ["Matched", ...]
|
30
30
|
|
31
|
+
### Cleanup
|
32
|
+
|
33
|
+
Thou canst clean up the handlers and even events with the methods 'purge_handlers', and 'purge_events' as follows:
|
34
|
+
|
35
|
+
t.on_event do |args|
|
36
|
+
"Matched"
|
37
|
+
end
|
38
|
+
|
39
|
+
t.purge_handlers :event
|
40
|
+
# or:
|
41
|
+
t.purge_handlers
|
42
|
+
|
43
|
+
t.event :event # => []
|
44
|
+
|
45
|
+
and events:
|
46
|
+
|
47
|
+
t.on_event do |args|
|
48
|
+
"Matched"
|
49
|
+
end
|
50
|
+
|
51
|
+
t.purge_events :event
|
52
|
+
|
53
|
+
t.event :event # => exception Eventer::UnknownEventError
|
54
|
+
|
31
55
|
# Copyright
|
32
56
|
|
33
|
-
Copyright (c) 2011 Malo Skrylevo
|
57
|
+
Copyright (c) 2011 Malo Skrylevo.
|
34
58
|
See LICENSE for details.
|
35
|
-
|
data/README.md
CHANGED
@@ -29,9 +29,31 @@ Eventer есть простой движокъ для управленія со
|
|
29
29
|
|
30
30
|
t.event_rs :event, args... # -> ["Matched", ...]
|
31
31
|
|
32
|
-
|
32
|
+
### Очистка
|
33
33
|
|
34
|
-
|
35
|
-
Зри LICENSE за подробностями.
|
34
|
+
Очистить обработчики или сами событія можно съ помощью методовъ 'purge_handlers' и 'purge_events' такъ:
|
36
35
|
|
36
|
+
t.on_event do |args|
|
37
|
+
"Matched"
|
38
|
+
end
|
37
39
|
|
40
|
+
t.purge_handlers :event
|
41
|
+
# или такъ:
|
42
|
+
t.purge_handlers
|
43
|
+
|
44
|
+
t.event :event # => []
|
45
|
+
|
46
|
+
и событія:
|
47
|
+
|
48
|
+
t.on_event do |args|
|
49
|
+
"Matched"
|
50
|
+
end
|
51
|
+
|
52
|
+
t.purge_events :event
|
53
|
+
|
54
|
+
t.event :event # => исключеніе Eventer::UnknownEventError
|
55
|
+
|
56
|
+
# Права
|
57
|
+
|
58
|
+
Авторскія и исключительныя права (а) 2011 Малъ Скрылевъ.
|
59
|
+
Зри LICENSE за подробностями.
|
data/lib/eventer.rb
CHANGED
@@ -23,14 +23,12 @@ public
|
|
23
23
|
def event(event, *args)
|
24
24
|
res = {}
|
25
25
|
|
26
|
-
if @__events__
|
27
|
-
|
28
|
-
|
29
|
-
res[event_h] = event_h.call(*args)
|
30
|
-
end
|
31
|
-
else
|
32
|
-
[]
|
26
|
+
if @__events__ && @__events__[event]
|
27
|
+
@__events__[event].each do |event_h|
|
28
|
+
res[event_h] = event_h.call(*args)
|
33
29
|
end
|
30
|
+
elsif self.methods.include?( eval ":on_#{event}" )
|
31
|
+
return []
|
34
32
|
else
|
35
33
|
raise UnknownEventError.new event
|
36
34
|
end
|
@@ -39,9 +37,18 @@ public
|
|
39
37
|
end
|
40
38
|
|
41
39
|
def purge_events(*events)
|
42
|
-
(events.empty? ? @__events__ : events).each do |e|
|
43
|
-
|
44
|
-
|
40
|
+
(events.empty? ? @__events__.keys : events).each do |e|
|
41
|
+
self.class.class_eval "undef_method :on_#{e}"
|
42
|
+
@__events__.delete(e)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def purge_handlers(*events)
|
47
|
+
if @__events__
|
48
|
+
(events.empty? ? @__events__.keys : events).each do |e|
|
49
|
+
@__events__[e].clear if @__events__.key? e
|
50
|
+
end
|
51
|
+
end
|
45
52
|
end
|
46
53
|
|
47
54
|
def event_rs(event, *args)
|
data/lib/eventer/version.rb
CHANGED
data/spec/eventer_spec.rb
CHANGED
@@ -57,6 +57,96 @@ describe 'Eventer' do
|
|
57
57
|
|
58
58
|
raise "Event result isn't matched" if (not o) or (o != true)
|
59
59
|
end
|
60
|
-
end
|
61
60
|
|
61
|
+
it "Purge all event handlers" do
|
62
|
+
class Test
|
63
|
+
events :event
|
64
|
+
end
|
65
|
+
|
66
|
+
t = Test.new
|
67
|
+
|
68
|
+
t.on_event do |args|
|
69
|
+
"Matched"
|
70
|
+
end
|
71
|
+
|
72
|
+
t.purge_handlers
|
73
|
+
|
74
|
+
o = t.event_rs :event
|
75
|
+
|
76
|
+
raise "Event result isn't matched" if o != [ ]
|
77
|
+
end
|
78
|
+
|
79
|
+
it "Purge the specific event handlers" do
|
80
|
+
class Test
|
81
|
+
events :event
|
82
|
+
end
|
83
|
+
|
84
|
+
t = Test.new
|
85
|
+
|
86
|
+
t.on_event do |args|
|
87
|
+
"Matched"
|
88
|
+
end
|
89
|
+
|
90
|
+
t.purge_handlers :event
|
91
|
+
|
92
|
+
o = t.event_rs :event
|
93
|
+
|
94
|
+
raise "Event result isn't matched" if o != [ ]
|
95
|
+
end
|
96
|
+
|
97
|
+
it "Purge all events" do
|
98
|
+
class Test
|
99
|
+
events :event
|
100
|
+
end
|
101
|
+
|
102
|
+
t = Test.new
|
103
|
+
|
104
|
+
t.on_event do |args|
|
105
|
+
"Matched"
|
106
|
+
end
|
107
|
+
|
108
|
+
t.purge_events
|
109
|
+
|
110
|
+
o = begin
|
111
|
+
t.event_rs :event
|
112
|
+
rescue Eventer::UnknownEventError
|
113
|
+
true
|
114
|
+
end
|
115
|
+
|
116
|
+
raise "Event result isn't matched" if (not o) or (o != true)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "Purge the specific event" do
|
120
|
+
class Test
|
121
|
+
events :event
|
122
|
+
end
|
123
|
+
|
124
|
+
t = Test.new
|
125
|
+
|
126
|
+
t.on_event do |args|
|
127
|
+
"Matched"
|
128
|
+
end
|
62
129
|
|
130
|
+
t.purge_events :event
|
131
|
+
|
132
|
+
o = begin
|
133
|
+
t.event_rs :event
|
134
|
+
rescue Eventer::UnknownEventError
|
135
|
+
true
|
136
|
+
end
|
137
|
+
|
138
|
+
raise "Event result isn't matched" if (not o) or (o != true)
|
139
|
+
end
|
140
|
+
|
141
|
+
it "Handler isn't defined" do
|
142
|
+
class Test
|
143
|
+
events :event
|
144
|
+
end
|
145
|
+
|
146
|
+
t = Test.new
|
147
|
+
|
148
|
+
o = t.event_rs :event
|
149
|
+
|
150
|
+
raise "Event result isn't matched" if o != [ ]
|
151
|
+
end
|
152
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eventer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-05-
|
12
|
+
date: 2011-05-18 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
|
-
requirement: &
|
16
|
+
requirement: &69582660 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *69582660
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &69582430 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 2.0.1
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *69582430
|
36
36
|
description: eventer is the simpest event throwing engine
|
37
37
|
email:
|
38
38
|
- 3aHyga@gmail.com
|
@@ -40,9 +40,11 @@ executables: []
|
|
40
40
|
extensions: []
|
41
41
|
extra_rdoc_files: []
|
42
42
|
files:
|
43
|
+
- .document
|
44
|
+
- .gitignore
|
45
|
+
- .rspec
|
43
46
|
- CHANGES.md
|
44
47
|
- Gemfile
|
45
|
-
- Gemfile.lock
|
46
48
|
- LICENSE
|
47
49
|
- README.en.md
|
48
50
|
- README.md
|
data/Gemfile.lock
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
eventer (0.0.2)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: http://rubygems.org/
|
8
|
-
specs:
|
9
|
-
diff-lcs (1.1.2)
|
10
|
-
rspec (2.0.1)
|
11
|
-
rspec-core (~> 2.0.1)
|
12
|
-
rspec-expectations (~> 2.0.1)
|
13
|
-
rspec-mocks (~> 2.0.1)
|
14
|
-
rspec-core (2.0.1)
|
15
|
-
rspec-expectations (2.0.1)
|
16
|
-
diff-lcs (>= 1.1.2)
|
17
|
-
rspec-mocks (2.0.1)
|
18
|
-
rspec-core (~> 2.0.1)
|
19
|
-
rspec-expectations (~> 2.0.1)
|
20
|
-
|
21
|
-
PLATFORMS
|
22
|
-
ruby
|
23
|
-
|
24
|
-
DEPENDENCIES
|
25
|
-
bundler (>= 1.0.0)
|
26
|
-
eventer!
|
27
|
-
rspec (~> 2.0.1)
|