notifyhub 0.0.2 → 0.0.3
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.
- checksums.yaml +7 -0
- data/CHANGELOG.rdoc +3 -0
- data/README.rdoc +7 -7
- data/doc/Notify.html +18 -18
- data/doc/NotifyHub/NotFound.html +2 -2
- data/doc/NotifyHub/Redefining.html +2 -2
- data/doc/NotifyHub.html +171 -100
- data/doc/NotifySet.html +52 -52
- data/doc/_index.html +1 -1
- data/doc/file.CHANGELOG.html +5 -2
- data/doc/file.README.html +11 -11
- data/doc/index.html +11 -11
- data/doc/method_list.html +16 -10
- data/doc/top-level-namespace.html +1 -1
- data/lib/notifyhub.rb +55 -46
- data/test/test_notifyhub.rb +11 -47
- metadata +26 -36
- data/Rakefile +0 -28
data/lib/notifyhub.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
# NotifyHub is a callback facility. NotifyHub is used by the informer
|
2
|
-
# to notify clients about arbitrary events in the informer. NotifyHub
|
3
|
-
# contains notification sets (NotifySet).
|
1
|
+
# {NotifyHub} is a callback facility. {NotifyHub} is used by the informer
|
2
|
+
# to notify clients about arbitrary events in the informer. {NotifyHub}
|
3
|
+
# contains notification sets ({NotifySet}).
|
4
4
|
#
|
5
|
-
# NotifySet is identified by set ID and it can include one or many
|
6
|
-
# notifications (Notify). Client defines the action performed at
|
5
|
+
# {NotifySet} is identified by set ID and it can include one or many
|
6
|
+
# notifications ({Notify}). Client defines the action performed at
|
7
7
|
# notification (callback). Informer activates the notification when
|
8
8
|
# notification events occur.
|
9
9
|
#
|
10
10
|
# Notifications can be enabled/disabled on different levels
|
11
|
-
# (NotifyHub, NotifySet, and Notify).
|
11
|
+
# ({NotifyHub}, {NotifySet}, and {Notify}).
|
12
12
|
#
|
13
|
-
#
|
13
|
+
# Usage example:
|
14
14
|
#
|
15
15
|
# require 'notifyhub'
|
16
16
|
#
|
@@ -19,9 +19,9 @@
|
|
19
19
|
#
|
20
20
|
# # Handle to NotifyHub.
|
21
21
|
# attr_accessor :hub
|
22
|
-
#
|
22
|
+
#
|
23
23
|
# def initialize
|
24
|
-
# # Create NotifyHub.
|
24
|
+
# # Create NotifyHub with 3 callbacks.
|
25
25
|
# @hub = NotifyHub.declare( :store, :load, :na )
|
26
26
|
# end
|
27
27
|
#
|
@@ -48,14 +48,18 @@
|
|
48
48
|
#
|
49
49
|
# # Setup notify action for load.
|
50
50
|
# storage.hub[ :load ].action do |data|
|
51
|
-
# puts "load:
|
51
|
+
# puts "load: #{data}"
|
52
52
|
# end
|
53
53
|
#
|
54
54
|
#
|
55
55
|
# # Use storage and get notifications.
|
56
56
|
# storage.store( "my data" )
|
57
57
|
# data = storage.load
|
58
|
-
|
58
|
+
#
|
59
|
+
#
|
60
|
+
# Produces:
|
61
|
+
# store: my data
|
62
|
+
# load: my data
|
59
63
|
class NotifyHub
|
60
64
|
|
61
65
|
|
@@ -63,14 +67,14 @@ class NotifyHub
|
|
63
67
|
attr_accessor :autodeclare
|
64
68
|
|
65
69
|
|
66
|
-
# Non-existing Notify error.
|
70
|
+
# Non-existing {Notify} error.
|
67
71
|
class NotFound < RuntimeError; end
|
68
72
|
|
69
|
-
# Redefining Notify error.
|
73
|
+
# Redefining {Notify} error.
|
70
74
|
class Redefining < RuntimeError; end
|
71
75
|
|
72
76
|
|
73
|
-
# Create NotifyHub and declare sets.
|
77
|
+
# Create {NotifyHub} and declare sets.
|
74
78
|
#
|
75
79
|
# @param id [Array<Symbol>] Notify set(s).
|
76
80
|
def NotifyHub.declare( *id )
|
@@ -78,7 +82,7 @@ class NotifyHub
|
|
78
82
|
end
|
79
83
|
|
80
84
|
|
81
|
-
# Create NotifyHub and with autodeclare for sets. Declare sets
|
85
|
+
# Create {NotifyHub} and with autodeclare for sets. Declare sets
|
82
86
|
# automatically at action registration.
|
83
87
|
#
|
84
88
|
# @param id [Array<Symbol>] Notify set(s).
|
@@ -89,7 +93,7 @@ class NotifyHub
|
|
89
93
|
end
|
90
94
|
|
91
95
|
|
92
|
-
# Create NotifyHub and run block with it.
|
96
|
+
# Create {NotifyHub} and run block with it.
|
93
97
|
#
|
94
98
|
# @yield Block to run with NotifyHub.
|
95
99
|
def NotifyHub.create( &blk )
|
@@ -99,7 +103,7 @@ class NotifyHub
|
|
99
103
|
end
|
100
104
|
cg
|
101
105
|
end
|
102
|
-
|
106
|
+
|
103
107
|
|
104
108
|
# Instantiation.
|
105
109
|
#
|
@@ -111,7 +115,7 @@ class NotifyHub
|
|
111
115
|
end
|
112
116
|
|
113
117
|
|
114
|
-
# Declare Notify by set. Multiple notifiers can exist per set.
|
118
|
+
# Declare {Notify} by set. Multiple notifiers can exist per set.
|
115
119
|
#
|
116
120
|
# @param id [Array<Symbol>] Notify set id(s).
|
117
121
|
def declare( *id )
|
@@ -125,19 +129,19 @@ class NotifyHub
|
|
125
129
|
end
|
126
130
|
|
127
131
|
|
128
|
-
# Register action to NotifySet. Multiple notifies can
|
132
|
+
# Register action to {NotifySet}. Multiple notifies can
|
129
133
|
# exist per set.
|
130
134
|
#
|
131
135
|
# @param id [Symbol] Notify set id (class).
|
132
136
|
# @param action [Block] Notify action.
|
133
137
|
def action( id, &action )
|
134
138
|
useSet( id ) do |set|
|
135
|
-
set.action( &action )
|
139
|
+
set.action( &action )
|
136
140
|
end
|
137
141
|
end
|
138
142
|
|
139
|
-
alias register action
|
140
|
-
alias with action
|
143
|
+
alias register action
|
144
|
+
alias with action
|
141
145
|
|
142
146
|
|
143
147
|
# Remove all or one Notify.
|
@@ -151,7 +155,7 @@ class NotifyHub
|
|
151
155
|
end
|
152
156
|
|
153
157
|
|
154
|
-
# Enable/disable Notify set or all if not set.
|
158
|
+
# Enable/disable {Notify} set or all if not set.
|
155
159
|
#
|
156
160
|
# @param id [Symbol] Notify set id (all if nil given).
|
157
161
|
# @param value [Boolean] Enable with true and disable with false.
|
@@ -166,9 +170,9 @@ class NotifyHub
|
|
166
170
|
end
|
167
171
|
end
|
168
172
|
end
|
169
|
-
|
170
|
-
|
171
|
-
# Run all notifiers in Notify set.
|
173
|
+
|
174
|
+
|
175
|
+
# Run all notifiers in {Notify} set.
|
172
176
|
#
|
173
177
|
# @param id [Symbol] Notify set id (class).
|
174
178
|
# @param args [Array<Object>] Arguments for notifiers.
|
@@ -179,7 +183,7 @@ class NotifyHub
|
|
179
183
|
end
|
180
184
|
|
181
185
|
|
182
|
-
# Get NotifySet by ID.
|
186
|
+
# Get {NotifySet} by ID.
|
183
187
|
#
|
184
188
|
# @param id [Symbol] Set ID.
|
185
189
|
# @return [NotifySet] Set.
|
@@ -190,7 +194,7 @@ class NotifyHub
|
|
190
194
|
end
|
191
195
|
|
192
196
|
|
193
|
-
# Get list of NotifySet IDs.
|
197
|
+
# Get list of {NotifySet} IDs.
|
194
198
|
#
|
195
199
|
# @return [Array<Symbol>] NotifySet IDs.
|
196
200
|
def ids
|
@@ -201,7 +205,7 @@ class NotifyHub
|
|
201
205
|
|
202
206
|
private
|
203
207
|
|
204
|
-
# Check that NotifySet exists (or create it).
|
208
|
+
# Check that {NotifySet} exists (or create it).
|
205
209
|
def withSet( id, &blk )
|
206
210
|
if @set[id]
|
207
211
|
yield @set[ id ]
|
@@ -211,9 +215,9 @@ class NotifyHub
|
|
211
215
|
end
|
212
216
|
|
213
217
|
|
214
|
-
# Check that NotifySet exists (or create it).
|
218
|
+
# Check that {NotifySet} exists (or create it).
|
215
219
|
def useSet( id, &blk )
|
216
|
-
|
220
|
+
|
217
221
|
if @set[id] || @autodeclare
|
218
222
|
|
219
223
|
unless @set[id]
|
@@ -228,17 +232,18 @@ class NotifyHub
|
|
228
232
|
|
229
233
|
end
|
230
234
|
end
|
231
|
-
|
235
|
+
|
232
236
|
end
|
233
237
|
|
234
238
|
|
235
239
|
|
236
|
-
# Notify object that includes disable/enable features.
|
240
|
+
# {Notify} object container that includes disable/enable features.
|
237
241
|
class NotifySet
|
238
|
-
|
239
|
-
|
242
|
+
|
243
|
+
|
244
|
+
# Enable/disable {NotifySet}.
|
240
245
|
attr_accessor :enable
|
241
|
-
|
246
|
+
|
242
247
|
|
243
248
|
# Instantiation.
|
244
249
|
#
|
@@ -248,9 +253,9 @@ class NotifySet
|
|
248
253
|
@enable = true
|
249
254
|
@list = []
|
250
255
|
end
|
251
|
-
|
252
256
|
|
253
|
-
|
257
|
+
|
258
|
+
# Enable/disable {NotifySet}.
|
254
259
|
#
|
255
260
|
# @param value [Boolean] Enable with true and disable with false.
|
256
261
|
def enable( value )
|
@@ -258,22 +263,22 @@ class NotifySet
|
|
258
263
|
end
|
259
264
|
|
260
265
|
|
261
|
-
# Register Notify.
|
266
|
+
# Register {Notify}.
|
262
267
|
#
|
263
|
-
# @param action [Block] Notify action.
|
268
|
+
# @param action [Block] {Notify} action.
|
264
269
|
def action( &action )
|
265
270
|
n = Notify.new( &action )
|
266
271
|
@list.push n
|
267
272
|
n
|
268
273
|
end
|
269
274
|
|
270
|
-
alias register action
|
271
|
-
alias with action
|
275
|
+
alias register action
|
276
|
+
alias with action
|
272
277
|
|
273
278
|
|
274
279
|
# Remove all or one Notify.
|
275
280
|
#
|
276
|
-
# @param notify [Notify] Notify to remove (all if not given).
|
281
|
+
# @param notify [Notify] {Notify} to remove (all if not given).
|
277
282
|
def remove( notify = nil )
|
278
283
|
if notify
|
279
284
|
@list.delete( notify )
|
@@ -282,7 +287,7 @@ class NotifySet
|
|
282
287
|
end
|
283
288
|
end
|
284
289
|
|
285
|
-
# Run all notifiers in
|
290
|
+
# Run all notifiers in {NotifySet}.
|
286
291
|
#
|
287
292
|
# @param args [Array<Object>] Arguments for notifiers.
|
288
293
|
# @return [Array<Object>] Array or single callback return value.
|
@@ -312,7 +317,7 @@ class NotifySet
|
|
312
317
|
end
|
313
318
|
|
314
319
|
|
315
|
-
# Get Notify by index.
|
320
|
+
# Get {Notify} by index.
|
316
321
|
def []( idx )
|
317
322
|
@list[ idx ]
|
318
323
|
end
|
@@ -347,7 +352,7 @@ class Notify
|
|
347
352
|
end
|
348
353
|
|
349
354
|
|
350
|
-
# Enable/disable Notify.
|
355
|
+
# Enable/disable {Notify}.
|
351
356
|
#
|
352
357
|
# @param value [Boolean] Enable with true and disable with false.
|
353
358
|
def enable( value )
|
@@ -355,3 +360,7 @@ class Notify
|
|
355
360
|
end
|
356
361
|
|
357
362
|
end
|
363
|
+
|
364
|
+
|
365
|
+
# Include version definitions.
|
366
|
+
require_relative 'version'
|
data/test/test_notifyhub.rb
CHANGED
@@ -1,57 +1,15 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'notifyhub'
|
3
3
|
|
4
|
-
# # Create class that includes interesting events.
|
5
|
-
# class Storage
|
6
|
-
#
|
7
|
-
# # Handle to NotifyHub.
|
8
|
-
# attr_accessor :hub
|
9
|
-
#
|
10
|
-
# def initialize
|
11
|
-
# # Create NotifyHub.
|
12
|
-
# @hub = NotifyHub.declare( :store, :load, :na )
|
13
|
-
# end
|
14
|
-
#
|
15
|
-
# # Store data and notify clients.
|
16
|
-
# def store( data )
|
17
|
-
# @data = data
|
18
|
-
# @hub[ :store ].notify( @data )
|
19
|
-
# end
|
20
|
-
#
|
21
|
-
# # Load data and notify clients.
|
22
|
-
# def load
|
23
|
-
# @hub[ :load ].notify( @data )
|
24
|
-
# @data
|
25
|
-
# end
|
26
|
-
# end
|
27
|
-
#
|
28
|
-
#
|
29
|
-
# storage = Storage.new
|
30
|
-
#
|
31
|
-
# # Setup notify action for store.
|
32
|
-
# storage.hub[ :store ].action do |data|
|
33
|
-
# puts "store: #{data}"
|
34
|
-
# end
|
35
|
-
#
|
36
|
-
# # Setup notify action for load.
|
37
|
-
# storage.hub[ :load ].action do |data|
|
38
|
-
# puts "load: #{data}"
|
39
|
-
# end
|
40
|
-
#
|
41
|
-
#
|
42
|
-
# # Use storage and get notifications.
|
43
|
-
# storage.store( "my data" )
|
44
|
-
# data = storage.load
|
45
|
-
|
46
4
|
class NotifyHubTest < Test::Unit::TestCase
|
47
|
-
|
5
|
+
|
48
6
|
|
49
7
|
# Create class that includes interesting events.
|
50
8
|
class Storage
|
51
9
|
|
52
10
|
# Handle to NotifyHub.
|
53
11
|
attr_accessor :hub
|
54
|
-
|
12
|
+
|
55
13
|
def initialize
|
56
14
|
# Create NotifyHub.
|
57
15
|
@hub = NotifyHub.declare( :store, :load, :na )
|
@@ -75,7 +33,7 @@ class NotifyHubTest < Test::Unit::TestCase
|
|
75
33
|
@check = {}
|
76
34
|
|
77
35
|
@n = NotifyHub.auto
|
78
|
-
|
36
|
+
|
79
37
|
@n[ :on ].action do |val|
|
80
38
|
@check[ :create_1 ] = val
|
81
39
|
end
|
@@ -140,7 +98,7 @@ class NotifyHubTest < Test::Unit::TestCase
|
|
140
98
|
n[ :off ].action do |val|
|
141
99
|
@check[ :create_3 ] = val
|
142
100
|
end
|
143
|
-
|
101
|
+
|
144
102
|
n[ :on ].notify( 1 )
|
145
103
|
n.notify( :off, 2 )
|
146
104
|
|
@@ -183,7 +141,7 @@ class NotifyHubTest < Test::Unit::TestCase
|
|
183
141
|
@n[ :off ].notify( 2 )
|
184
142
|
assert_equal( 1, @check[ :create_1 ] )
|
185
143
|
assert_equal( 1, @check[ :create_2 ] )
|
186
|
-
assert_equal( 2, @check[ :create_3 ] )
|
144
|
+
assert_equal( 2, @check[ :create_3 ] )
|
187
145
|
end
|
188
146
|
|
189
147
|
|
@@ -226,4 +184,10 @@ class NotifyHubTest < Test::Unit::TestCase
|
|
226
184
|
|
227
185
|
end
|
228
186
|
|
187
|
+
|
188
|
+
def test_ids
|
189
|
+
assert_equal( [ :on, :off ], @n.ids )
|
190
|
+
end
|
191
|
+
|
192
|
+
|
229
193
|
end
|
metadata
CHANGED
@@ -1,92 +1,82 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notifyhub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Tero Isannainen
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-11-23 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
|
-
description:
|
15
|
-
|
13
|
+
description: |-
|
14
|
+
NotifyHub is a callback facility. NotifyHub is used by the informer
|
16
15
|
to notify clients about arbitrary events in the informer. NotifyHub
|
17
|
-
|
18
16
|
contains notification sets (NotifySet).
|
19
17
|
|
20
|
-
|
21
18
|
NotifySet is identified by set ID and it can include one or many
|
22
|
-
|
23
19
|
notifications (Notify). Client defines the action performed at
|
24
|
-
|
25
20
|
notification (callback). Informer activates the notification when
|
26
|
-
|
27
21
|
notification events occur.
|
28
22
|
|
29
|
-
|
30
23
|
Notifications can be enabled/disabled on different levels
|
31
|
-
|
32
|
-
(NotifyHub, NotifySet, and Notify).'
|
24
|
+
(NotifyHub, NotifySet, and Notify).
|
33
25
|
email: tero.isannainen@gmail.com
|
34
26
|
executables: []
|
35
27
|
extensions: []
|
36
28
|
extra_rdoc_files:
|
37
29
|
- README.rdoc
|
38
30
|
files:
|
39
|
-
- README.rdoc
|
40
31
|
- CHANGELOG.rdoc
|
41
32
|
- LICENSE
|
42
|
-
-
|
43
|
-
- lib/notifyhub.rb
|
44
|
-
- test/test_notifyhub.rb
|
45
|
-
- doc/top-level-namespace.html
|
46
|
-
- doc/js/full_list.js
|
47
|
-
- doc/js/app.js
|
48
|
-
- doc/js/jquery.js
|
49
|
-
- doc/index.html
|
33
|
+
- README.rdoc
|
50
34
|
- doc/Master.html
|
51
35
|
- doc/Notify.html
|
36
|
+
- doc/NotifyHub.html
|
37
|
+
- doc/NotifyHub/NotFound.html
|
38
|
+
- doc/NotifyHub/Redefining.html
|
39
|
+
- doc/NotifySet.html
|
40
|
+
- doc/_index.html
|
41
|
+
- doc/class_list.html
|
52
42
|
- doc/css/common.css
|
53
43
|
- doc/css/full_list.css
|
54
44
|
- doc/css/style.css
|
45
|
+
- doc/file.CHANGELOG.html
|
55
46
|
- doc/file.README.html
|
56
|
-
- doc/method_list.html
|
57
47
|
- doc/file_list.html
|
58
|
-
- doc/NotifyHub/Redefining.html
|
59
|
-
- doc/NotifyHub/NotFound.html
|
60
|
-
- doc/NotifySet.html
|
61
|
-
- doc/NotifyHub.html
|
62
|
-
- doc/class_list.html
|
63
|
-
- doc/_index.html
|
64
|
-
- doc/file.CHANGELOG.html
|
65
48
|
- doc/frames.html
|
49
|
+
- doc/index.html
|
50
|
+
- doc/js/app.js
|
51
|
+
- doc/js/full_list.js
|
52
|
+
- doc/js/jquery.js
|
53
|
+
- doc/method_list.html
|
54
|
+
- doc/top-level-namespace.html
|
55
|
+
- lib/notifyhub.rb
|
56
|
+
- test/test_notifyhub.rb
|
66
57
|
homepage:
|
67
58
|
licenses:
|
68
59
|
- Ruby
|
60
|
+
metadata: {}
|
69
61
|
post_install_message: Check README...
|
70
62
|
rdoc_options: []
|
71
63
|
require_paths:
|
72
64
|
- lib
|
73
65
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
66
|
requirements:
|
76
|
-
- -
|
67
|
+
- - ">="
|
77
68
|
- !ruby/object:Gem::Version
|
78
69
|
version: 1.9.3
|
79
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
-
none: false
|
81
71
|
requirements:
|
82
|
-
- -
|
72
|
+
- - ">="
|
83
73
|
- !ruby/object:Gem::Version
|
84
74
|
version: '0'
|
85
75
|
requirements: []
|
86
76
|
rubyforge_project:
|
87
|
-
rubygems_version:
|
77
|
+
rubygems_version: 2.2.2
|
88
78
|
signing_key:
|
89
|
-
specification_version:
|
79
|
+
specification_version: 4
|
90
80
|
summary: NotifyHub is implementation of the Observer pattern using composition.
|
91
81
|
test_files: []
|
92
82
|
has_rdoc:
|
data/Rakefile
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'rake/testtask'
|
2
|
-
|
3
|
-
Rake::TestTask.new do |t|
|
4
|
-
t.libs << 'test'
|
5
|
-
end
|
6
|
-
|
7
|
-
desc "Run tests"
|
8
|
-
task :default => :test
|
9
|
-
|
10
|
-
task :cleanup_test do
|
11
|
-
sh "rm -rf test/test"
|
12
|
-
end
|
13
|
-
|
14
|
-
task :build => :doc do
|
15
|
-
sh "gem build notifyhub.gemspec"
|
16
|
-
end
|
17
|
-
|
18
|
-
task :doc do
|
19
|
-
sh "yardoc lib/* - README.rdoc CHANGELOG.rdoc"
|
20
|
-
end
|
21
|
-
|
22
|
-
task :publish do
|
23
|
-
if Dir.glob('notifyhub-*gem').length == 1
|
24
|
-
sh "gem push notifyhub*.gem"
|
25
|
-
else
|
26
|
-
raise "Multiple gems in the directory..."
|
27
|
-
end
|
28
|
-
end
|