eventable 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -144,6 +144,17 @@ This example shows you how you might actually use it in a multi-threaded environ
144
144
 
145
145
  ##Version History##
146
146
 
147
+ **2011.06.10**
148
+ Ver: 0.1.1
149
+
150
+ Features:
151
+ If events fired specifically returns true and returns false if it can't for whatever reason (e.g. no listeners registered).
152
+
153
+ Fixes:
154
+ * Throws error if event is fired and no listeners are registered (Thanks for bug report Benjamin Yu)
155
+ * Workaround for RubyGems pre 1.8.3 date bug that locks up all of RubyGems (Thanks again Benjamin Yu)
156
+
157
+
147
158
  **2011.06.06**
148
159
  Ver: 0.1.0
149
160
  Went crazy and just completely wrapped all calls that modify or read callbacks cache with an instance mutex.
@@ -1,5 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
+ # Kludge for older RubyGems not handling unparsable dates gracefully
4
+ # (psych 1.2.0 gem wouldn't build on test system so we're stuck with syck)
5
+ YAML::ENGINE.yamler = 'syck'
6
+ require "rubygems"
3
7
  require "eventable/version"
4
8
 
5
9
  Gem::Specification.new do |s|
@@ -7,13 +11,13 @@ Gem::Specification.new do |s|
7
11
  s.version = Eventable::VERSION
8
12
  s.authors = ["Mike Bethany"]
9
13
  s.email = ["mikbe.tk@gmail.com"]
10
- s.homepage = "http://mikbe.tk"
14
+ s.homepage = "http://mikbe.tk/projects#eventable"
11
15
  s.summary = %q{An incredibly simple and easy to use event mixin module.}
12
- s.description = %q{Provides an easy to use and understand event model. If you want a simple way to add events to your classes without a bunch of other unrelated IO stuff this is the solution for you. (If you want to monitor IO events check out EventMachine)}
16
+ s.description = %q{Provides an easy to use and understand event model. If you want a simple, light-weight way to add events to your classes without a bunch of unrelated IO stuff this is the solution for you. (If you want to monitor IO events check out EventMachine)}
13
17
 
14
18
  s.add_development_dependency('rspec', "~>2.6")
15
19
 
16
20
  s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
18
22
  s.require_paths = ["lib"]
19
23
  end
@@ -33,9 +33,10 @@ module Eventable
33
33
  # When the event happens the class where it happens runs this
34
34
  def fire_event(event, *return_value, &block)
35
35
  # We don't want the callback array being altered when we're trying to read it
36
+ @mutex ||= Mutex.new
36
37
  @mutex.synchronize{
37
38
 
38
- return false unless @callbacks[event] && !@callbacks[event].empty?
39
+ return false unless @callbacks && @callbacks[event] && !@callbacks[event].empty?
39
40
 
40
41
  @callbacks[event].each do |listener_id, callbacks|
41
42
  begin
@@ -47,6 +48,7 @@ module Eventable
47
48
  end
48
49
  end
49
50
  }
51
+ true
50
52
  end
51
53
 
52
54
  # Allows an object to listen for an event and have a callback run when the event happens
@@ -82,6 +84,7 @@ module Eventable
82
84
 
83
85
  # Allows objects to stop listening to events
84
86
  def unregister_for_event(args)
87
+ @mutex ||= Mutex.new
85
88
  @mutex.synchronize {
86
89
  event = args[:event]
87
90
  return unless @callbacks && @callbacks[event]
@@ -1,3 +1,3 @@
1
1
  module Eventable
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -158,6 +158,11 @@ describe Eventable do
158
158
  end
159
159
 
160
160
  context "when unregistering for an event" do
161
+
162
+ it "should not throw an error if unregistering for an event you weren't registered for" do
163
+ # Is this supporting sloppy programming(bad) or lazy programming(good)?
164
+ lambda{@evented.unregister_for_event(event: :stuff_happens, listener: @listener, callback: :callback)}.should_not raise_error
165
+ end
161
166
 
162
167
  it "should remove a callback" do
163
168
  @evented.register_for_event(event: :stuff_happens, listener: @listener, callback: :callback)
@@ -187,6 +192,21 @@ describe Eventable do
187
192
  end
188
193
 
189
194
  context "when an event is fired" do
195
+
196
+ it "should return false if the event did not fire" do
197
+ @evented.do_event
198
+ @evented.do_event.should be_false
199
+ end
200
+
201
+ it "should return true if the event did fire" do
202
+ @evented.register_for_event(event: :stuff_happens, listener: @listener, callback: :callback)
203
+ @evented.do_event.should be_true
204
+ end
205
+
206
+ it "should not throw an error if no listeners have been registered for an event" do
207
+ @evented.do_event
208
+ lambda{@evented.do_event}.should_not raise_error
209
+ end
190
210
 
191
211
  it "should call back the specified method when the event is fired" do
192
212
  @evented.register_for_event(event: :stuff_happens, listener: @listener, callback: :callback)
metadata CHANGED
@@ -1,36 +1,38 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: eventable
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.0
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 0.1.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Mike Bethany
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-06 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
12
+
13
+ date: 2011-06-10 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
15
16
  name: rspec
16
- requirement: &2156180860 !ruby/object:Gem::Requirement
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
17
19
  none: false
18
- requirements:
20
+ requirements:
19
21
  - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '2.6'
22
+ - !ruby/object:Gem::Version
23
+ version: "2.6"
22
24
  type: :development
23
- prerelease: false
24
- version_requirements: *2156180860
25
- description: Provides an easy to use and understand event model. If you want a simple
26
- way to add events to your classes without a bunch of other unrelated IO stuff this
27
- is the solution for you. (If you want to monitor IO events check out EventMachine)
28
- email:
25
+ version_requirements: *id001
26
+ description: Provides an easy to use and understand event model. If you want a simple, light-weight way to add events to your classes without a bunch of unrelated IO stuff this is the solution for you. (If you want to monitor IO events check out EventMachine)
27
+ email:
29
28
  - mikbe.tk@gmail.com
30
29
  executables: []
30
+
31
31
  extensions: []
32
+
32
33
  extra_rdoc_files: []
33
- files:
34
+
35
+ files:
34
36
  - .gitignore
35
37
  - Gemfile
36
38
  - LICENSE.txt
@@ -48,30 +50,32 @@ files:
48
50
  - lib/eventable/version.rb
49
51
  - spec/eventable/eventable_spec.rb
50
52
  - spec/spec_helper.rb
51
- homepage: http://mikbe.tk
53
+ homepage: http://mikbe.tk/projects#eventable
52
54
  licenses: []
55
+
53
56
  post_install_message:
54
57
  rdoc_options: []
55
- require_paths:
58
+
59
+ require_paths:
56
60
  - lib
57
- required_ruby_version: !ruby/object:Gem::Requirement
61
+ required_ruby_version: !ruby/object:Gem::Requirement
58
62
  none: false
59
- requirements:
60
- - - ! '>='
61
- - !ruby/object:Gem::Version
62
- version: '0'
63
- required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
68
  none: false
65
- requirements:
66
- - - ! '>='
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
69
73
  requirements: []
74
+
70
75
  rubyforge_project:
71
76
  rubygems_version: 1.8.5
72
77
  signing_key:
73
78
  specification_version: 3
74
79
  summary: An incredibly simple and easy to use event mixin module.
75
- test_files:
76
- - spec/eventable/eventable_spec.rb
77
- - spec/spec_helper.rb
80
+ test_files: []
81
+