onfire 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.textile ADDED
@@ -0,0 +1,9 @@
1
+ h2. 0.1.2
2
+
3
+ h3. Changes
4
+ * Added #event_for to extract the event creation in #trigger to a factory method. Useful for creating your own event instance.
5
+
6
+ h2. 0.1.1
7
+
8
+ h3. Bugfixes
9
+ * @#fire@ now accepts additional payload data which is added to the event.
data/lib/onfire.rb CHANGED
@@ -15,7 +15,7 @@ module Onfire
15
15
  end
16
16
 
17
17
  def fire(event_type, data={})
18
- bubble_event Event.new(event_type, self, data)
18
+ bubble_event event_for(event_type, self, data)
19
19
  end
20
20
 
21
21
  def bubble_event(event)
@@ -40,13 +40,18 @@ module Onfire
40
40
  @event_table ||= Onfire::EventTable.new
41
41
  end
42
42
 
43
- protected
44
- def attach_event_handler(proc, table_options)
45
- event_table.add_handler(proc, table_options)
46
- end
47
-
48
- # Get all handlers from self for the passed event.
49
- def local_event_handlers(event)
50
- event_table.all_handlers_for(event.type, event.source)
51
- end
43
+ protected
44
+ def attach_event_handler(proc, table_options)
45
+ event_table.add_handler(proc, table_options)
46
+ end
47
+
48
+ # Get all handlers from self for the passed event.
49
+ def local_event_handlers(event)
50
+ event_table.all_handlers_for(event.type, event.source)
51
+ end
52
+
53
+ # Factory method for creating the event. Override if you want your own event.
54
+ def event_for(*args)
55
+ Event.new(*args)
56
+ end
52
57
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Onfire
4
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
5
3
  end
data/test/onfire_test.rb CHANGED
@@ -190,7 +190,7 @@ class OnfireTest < Test::Unit::TestCase
190
190
 
191
191
  context "calling #fire" do
192
192
  setup do
193
- @obj = mock
193
+ @obj = mock
194
194
  end
195
195
 
196
196
  should "be of no relevance when there are no handlers attached" do
@@ -251,6 +251,36 @@ class OnfireTest < Test::Unit::TestCase
251
251
 
252
252
  assert_equal ["You look like I need a drink."], @obj.list
253
253
  end
254
+
255
+ # FUNCTIONAL: (onfire context)
256
+ context "#event_for" do
257
+ setup do
258
+ @obj.on :thirsty do |evt|
259
+ @obj.list << evt
260
+ end
261
+ end
262
+
263
+ should "respect #event_for" do
264
+ @obj.fire :thirsty
265
+
266
+ assert_kind_of Onfire::Event, @obj.list.first
267
+ end
268
+
269
+ # FUNCTIONAL: (onfire context)
270
+ should "respect an overridden #event_for" do
271
+ class LocalEvent < Onfire::Event
272
+ end
273
+
274
+ @obj.instance_eval do
275
+ def event_for(*args)
276
+ LocalEvent.new(*args)
277
+ end
278
+ end
279
+ @obj.fire :thirsty
280
+
281
+ assert_kind_of LocalEvent, @obj.list.first
282
+ end
283
+ end
254
284
  end
255
285
 
256
286
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nick Sutterer
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-02 00:00:00 +01:00
17
+ date: 2011-02-08 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -28,6 +28,7 @@ extensions: []
28
28
  extra_rdoc_files: []
29
29
 
30
30
  files:
31
+ - CHANGES.textile
31
32
  - Gemfile
32
33
  - README.textile
33
34
  - Rakefile