publisher 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 CHANGED
@@ -1,3 +1,7 @@
1
+ == 1.1.1 / 2007-12-28
2
+
3
+ * Subclasses now inherit the events supported by their ancestors
4
+
1
5
  == 1.1.0 / 2007-11-21
2
6
 
3
7
  * Moved publisher out of internal AO repository into atomicobject.rb project.
data/README.txt CHANGED
@@ -1,12 +1,14 @@
1
- publisher
2
- * http://rubyforge.org/projects/atomicobjectrb/
3
- * http://atomicobjectrb.rubyforge.org/constructor
1
+ == Publisher
2
+
3
+ * http://atomicobject.github.com/publisher
4
+ * http://github.com/atomicobject/publisher
5
+ * http://gemcutter.com/gems/publisher
4
6
 
5
7
  == DESCRIPTION:
6
8
 
7
9
  publisher is a module for extending a class with event subscription and firing capabilities. This is helpful for implementing objects that participate in the Observer design pattern.
8
10
 
9
- == FEATURES/PROBLEMS:
11
+ == FEATURES:
10
12
 
11
13
  * Nice syntax for declaring events that can be subscribed for
12
14
  * Convenient event firing syntax
@@ -73,3 +75,4 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
73
75
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
74
76
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
75
77
  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
78
+
data/Rakefile CHANGED
@@ -13,6 +13,9 @@ Rake::TestTask.new("test") { |t|
13
13
  t.verbose = true
14
14
  }
15
15
 
16
+ #
17
+ # Hoe stuff: rubyforge project release
18
+ #
16
19
  Hoe.new('publisher', Publisher::VERSION) do |p|
17
20
  p.rubyforge_name = 'atomicobjectrb'
18
21
  p.author = 'Atomic Object'
@@ -20,8 +23,14 @@ Hoe.new('publisher', Publisher::VERSION) do |p|
20
23
  p.summary = 'Event subscription and firing mechanism'
21
24
  p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
22
25
  p.url = p.paragraphs_of('README.txt', 1).first.gsub(/\* /,'').split(/\n/)
23
- # p.url = p.paragraphs_of('README.txt', 1).first.split(/\n/)[1..-1]
24
26
  p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
25
27
  end
26
28
 
27
- # vim: syntax=Ruby
29
+ if File.exists?("../tools/")
30
+ load "../tools/tasks/homepage.rake"
31
+ load "../tools/tasks/release_tagging.rake"
32
+ ReleaseTagging.new do |t|
33
+ t.package = "publisher"
34
+ t.version = Publisher::VERSION
35
+ end
36
+ end
data/lib/publisher.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # See README.txt for synopsis
2
2
  module Publisher
3
- VERSION = "1.1.0" #:nodoc:#
3
+ VERSION = "1.1.1" #:nodoc:#
4
4
 
5
5
  # Use this method (or one of the aliases) to declare which events you support
6
6
  # Once invoked, your class will have the neccessary supporting methods for subscribing and firing.
@@ -13,6 +13,19 @@ module Publisher
13
13
  alias :has_event :has_events
14
14
  alias :can_fire :has_events
15
15
 
16
+ def published_events
17
+ return @published_events if @published_events == :any_event_is_ok
18
+ my_events = @published_events || []
19
+ if self.superclass.respond_to?(:published_events)
20
+ inherited = self.superclass.published_events
21
+ if inherited == :any_event_is_ok
22
+ return :any_event_is_ok
23
+ end
24
+ my_events += self.superclass.published_events
25
+ end
26
+ my_events
27
+ end
28
+
16
29
  # Use this method to allow subscription and firing of arbitrary events.
17
30
  # This is convenient if, eg, your class has dynamic event names.
18
31
  # Don't use this unless you have to; it's better to declare your events if you
@@ -65,7 +78,8 @@ module Publisher
65
78
  # Does nothing if the current class supports the named event.
66
79
  # Raises RuntimeError otherwise.
67
80
  def ensure_valid(event) #:nodoc:#
68
- events = self.class.class_eval { @published_events }
81
+ # events = self.class.class_eval { @published_events }
82
+ events = self.class.published_events
69
83
  return if events == :any_event_is_ok
70
84
  raise "Event '#{event}' not available" unless events and events.include?(event)
71
85
  end
@@ -188,20 +188,6 @@ class PublisherTest < Test::Unit::TestCase
188
188
  assert_equal 'huh', out
189
189
  end
190
190
 
191
- # Cannot inherit events right now
192
- # class SomebodyKid < Somebody
193
- # end
194
- #
195
- # def test_inheriting_events
196
- # obj = SomebodyKid.new
197
- # out = nil
198
- # obj.on :eat_this do |food|
199
- # out = food
200
- # end
201
- # obj.go "taco"
202
- # assert_equal "taco", out
203
- # end
204
-
205
191
  def test_extending_publisher_doesnt_affect_normal_inheritance
206
192
  obj = Billy.new('wheel')
207
193
  assert_equal 'wheel', obj.chair
@@ -248,6 +234,56 @@ class PublisherTest < Test::Unit::TestCase
248
234
  assert_equal "burger", out1, "First subscription no go"
249
235
  assert_equal "burger", out2, "Second subscription no go"
250
236
  end
237
+
238
+ def test_subclasses_inherit_events
239
+ a = []
240
+ grampa = Grandfather.new
241
+ grampa.on :cannons do
242
+ a << "grampa's cannons"
243
+ end
244
+
245
+ dad = Dad.new
246
+ dad.on :cannons do
247
+ a << "dad's cannons"
248
+ end
249
+
250
+ dave = Dave.new
251
+ dave.on :cannons do
252
+ a << "dave's cannons"
253
+ end
254
+ dave.on :specific do
255
+ a << "dave's specific"
256
+ end
257
+
258
+ grampa.go
259
+ dad.go
260
+ dave.go
261
+ dave.doit
262
+
263
+ assert_equal [
264
+ "grampa's cannons",
265
+ "dad's cannons",
266
+ "dave's cannons",
267
+ "dave's specific"
268
+ ], a
269
+ end
270
+
271
+ def test_subclasses_inherit_wide_open_events
272
+ a = []
273
+ dynamo = Dynamo.new
274
+ dynamo.when :surprise do
275
+ a << "surprise"
276
+ end
277
+ dynamo.go(:surprise)
278
+
279
+ son = SonOfDynamo.new
280
+ son.when :hooray do
281
+ a << "hooray"
282
+ end
283
+ son.kick_it(:hooray)
284
+
285
+ assert_equal [ "surprise", "hooray" ], a
286
+ end
251
287
 
252
288
  #
253
289
  # HELPERS
@@ -355,4 +391,38 @@ class PublisherTest < Test::Unit::TestCase
355
391
  end
356
392
  end
357
393
 
394
+ class Grandfather
395
+ extend Publisher
396
+ can_fire :cannons
397
+
398
+ def go
399
+ fire :cannons
400
+ end
401
+ end
402
+
403
+ class Dad < Grandfather
404
+ end
405
+
406
+ class Dave < Dad
407
+ can_fire :specific
408
+
409
+ def doit
410
+ fire :specific
411
+ end
412
+ end
413
+
414
+ class Dynamo
415
+ extend Publisher
416
+ can_fire_anything
417
+ def go(sym)
418
+ fire sym
419
+ end
420
+ end
421
+
422
+ class SonOfDynamo < Dynamo
423
+ def kick_it(sym)
424
+ fire sym
425
+ end
426
+ end
427
+
358
428
  end
metadata CHANGED
@@ -1,27 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: publisher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- platform: ""
4
+ version: 1.1.1
5
+ platform: ruby
6
6
  authors:
7
7
  - Atomic Object
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2007-11-21 00:00:00 -05:00
12
+ date: 2009-11-08 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hoe
17
+ type: :development
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
20
21
  - - ">="
21
22
  - !ruby/object:Gem::Version
22
- version: 1.3.0
23
+ version: 2.3.3
23
24
  version:
24
- description: "== FEATURES/PROBLEMS: * Nice syntax for declaring events that can be subscribed for * Convenient event firing syntax * Subscribe / unsubscribe functionality * Several method name aliases give you the flexibility to make your code more readable (eg, *fire*, *notify*, *emit*) == SYNOPSIS: require 'rubygems' require 'publisher' class CustomerListHolder extend Publisher can_fire :customer_added, :list_cleared"
25
+ description: |-
26
+ == DESCRIPTION:
27
+
28
+ publisher is a module for extending a class with event subscription and firing capabilities. This is helpful for implementing objects that participate in the Observer design pattern.
29
+
30
+ == FEATURES:
31
+
32
+ * Nice syntax for declaring events that can be subscribed for
33
+ * Convenient event firing syntax
34
+ * Subscribe / unsubscribe functionality
35
+ * Several method name aliases give you the flexibility to make your code more readable (eg, *fire*, *notify*, *emit*)
36
+
37
+ == SYNOPSIS:
38
+
39
+ require 'rubygems'
40
+ require 'publisher'
25
41
  email: dev@atomicobject.com
26
42
  executables: []
27
43
 
@@ -40,7 +56,9 @@ files:
40
56
  - test/publisher_test.rb
41
57
  - test/test_helper.rb
42
58
  has_rdoc: true
43
- homepage: "== DESCRIPTION:"
59
+ homepage: http://atomicobject.github.com/publisher
60
+ licenses: []
61
+
44
62
  post_install_message:
45
63
  rdoc_options:
46
64
  - --main
@@ -62,9 +80,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
80
  requirements: []
63
81
 
64
82
  rubyforge_project: atomicobjectrb
65
- rubygems_version: 0.9.5
83
+ rubygems_version: 1.3.5
66
84
  signing_key:
67
- specification_version: 2
85
+ specification_version: 3
68
86
  summary: Event subscription and firing mechanism
69
87
  test_files:
70
88
  - test/test_helper.rb