eventable 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,7 +27,7 @@ Events and threads do not scale well past a certain point but that's OK; they ar
27
27
  ##Usage Instructions##
28
28
 
29
29
  * Include the module
30
- * **Important:** If you have an initialize method call `super` as first line (see below). If you don't have an initialize method you don't have to add one. Super is called automatically for you.
30
+ * **Important:** If you have an initialize method `super` must be the first line of that method (see below). If you don't have an initialize method you don't have to add one. Super is called automatically for you.
31
31
  * Add an event, e.g. `event :your_event`
32
32
  * Fire the event when it should be fired: `fire_event(:your_event)`
33
33
 
@@ -137,12 +137,11 @@ This example shows you how you might actually use it in a multi-threaded environ
137
137
  end
138
138
 
139
139
  def stuff_happened(stuff)
140
- splat = stuff
141
- puts "[#{splat[:parent_id]}] stuff_happened callback: #{splat[:some_value]}"
140
+ puts "[#{stuff[:parent_id]}] stuff_happened callback: #{stuff[:some_value]}"
142
141
  end
143
142
 
144
143
  def other_stuff_happened
145
- puts "[n/a] same_stuff_happened callback: n/a"
144
+ puts "[n/a] other_stuff_happened callback: n/a"
146
145
  end
147
146
 
148
147
  end
@@ -156,7 +155,9 @@ This example shows you how you might actually use it in a multi-threaded environ
156
155
  # or attach to events outside of a listener class
157
156
  evented.register_for_event(event: :other_stuff_happens, listener: listener, callback: :other_stuff_happened)
158
157
 
158
+ # Start firing off the events
159
159
  evented.start_other_stuff_happening
160
+
160
161
  (1..3).each do |index|
161
162
  listener.do_somestuff(index)
162
163
  puts "[#{index}] did some stuff, sleeping"
@@ -169,6 +170,17 @@ This example shows you how you might actually use it in a multi-threaded environ
169
170
 
170
171
  ##Version History##
171
172
 
173
+ **2011.07.05**
174
+ Ver: 0.1.4
175
+
176
+ Updates:
177
+
178
+ * Added running specs to rake tasks (Colin Gemmell)
179
+
180
+ Bug fixes:
181
+
182
+ * Did not accept initialization parameters so caused errors if your class inherited from another class that needed them. (Paul Strong)
183
+
172
184
  **2011.06.28**
173
185
  Ver: 0.1.3
174
186
 
@@ -179,24 +191,25 @@ This patches one of the last concurrency issues; if a callback takes a long time
179
191
 
180
192
  It's your responsiblity to make sure your callback works, as long as it does the callback thread will go out of scope (unless you retain it) and everyone is happy.
181
193
 
182
- **2011.06.17**
183
- Ver: 0.1.2
194
+ **2011.06.17**
195
+ Ver: 0.1.2
184
196
 
185
197
  Design updates/fixes:
186
198
 
187
199
  * Renamed most instance variables to help avoid name collisions.
188
- * Threadsafe mutex creation. Make sure you call `super` in your class's initialize method!
200
+ * Threadsafe mutex creation. Make sure you call `super` in your class's initialize method! (Robert Klemme)
189
201
 
190
202
  **2011.06.10**
191
203
  Ver: 0.1.1
192
204
 
193
205
  Features:
194
- If events fired specifically returns true and returns false if it can't for whatever reason (e.g. no listeners registered).
206
+
207
+ * If events fired specifically returns true and returns false if it can't for whatever reason (e.g. no listeners registered).
195
208
 
196
209
  Fixes:
197
210
 
198
- * Throws error if event is fired and no listeners are registered (Thanks for bug report Benjamin Yu)
199
- * Workaround for RubyGems pre 1.8.3 date bug that locks up all of RubyGems (Thanks again Benjamin Yu)
211
+ * Throws error if event is fired and no listeners are registered (Benjamin Yu)
212
+ * Workaround for RubyGems pre 1.8.3 date bug that locks up all of RubyGems (Benjamin Yu)
200
213
 
201
214
 
202
215
  **2011.06.06**
@@ -210,8 +223,9 @@ Releasing just to stop RubyGems.org from showing last beta instead of newest bet
210
223
 
211
224
  **2011.06.05**
212
225
  Ver: 0.1.0.beta2
213
- Wrapped #\_id2ref call in begin...rescue block.
214
- Added thread synchronization to calls that modify or read callbacks cache.
226
+
227
+ * Wrapped #\_id2ref call in begin...rescue block. (Evan Phoenix)
228
+ * Added thread synchronization to calls that modify or read callbacks cache.
215
229
 
216
230
  **2011.06.05**
217
231
  Ver: 0.1.0.beta1
@@ -229,4 +243,13 @@ Garbage collection safe:
229
243
 
230
244
  **2011.06.04**
231
245
  Ver: 0.0.1.alpha
232
- Just wrote it as a proof of concept.
246
+ Just wrote it as a proof of concept.
247
+
248
+
249
+ ##Patches/Pull requests##
250
+
251
+ * Fork the project.
252
+ * Make your feature addition or bug fix (**do not** alter whitespace unless that is a bug!)
253
+ * Add RSpecs for the fix/feature. If you don't have specs I can't add it.
254
+ * Commit your changes. (**do not** change the rakefile, version, or history)
255
+ * Send a pull request. I respond to pull request very, very quickly.
data/Rakefile CHANGED
@@ -1 +1,16 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc 'Default: run specs.'
5
+ task :default => :spec
6
+
7
+ desc "Run specs"
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.rspec_opts = %w[--color]
10
+ t.verbose = false
11
+ end
12
+
13
+ # Add running specs to the gem tasks
14
+ [:build, :install, :release].each do |task_name|
15
+ task task_name => :spec
16
+ end
@@ -30,7 +30,7 @@ module Eventable
30
30
  base.extend(EventableEventMethods)
31
31
  end
32
32
 
33
- def initialize
33
+ def initialize(*args)
34
34
  super
35
35
  @eventable_mutex = Mutex.new
36
36
  end
@@ -1,3 +1,3 @@
1
1
  module Eventable
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -10,7 +10,7 @@ describe Eventable do
10
10
  @listener = ListenClass.new
11
11
  end
12
12
 
13
- context "when inheriting eventable" do
13
+ context "when mixing in Eventable" do
14
14
 
15
15
  it "should not raise an error if class has no initialize method" do
16
16
  lambda{
@@ -50,6 +50,51 @@ describe Eventable do
50
50
  }.should raise_error(Eventable::Errors::SuperNotCalledInInitialize)
51
51
  end
52
52
 
53
+ context "and the class inherites from a class with initialization parameters" do
54
+
55
+ it "should not raise an error if they are optional and not given" do
56
+ class Baz
57
+ def initialize(attributes = nil, options = {})
58
+ end
59
+ end
60
+
61
+ class Qiz < Baz
62
+ include Eventable
63
+ end
64
+
65
+ expect{q = Qiz.new}.should_not raise_error
66
+ end
67
+
68
+ it "should not raise an error if they are required and given" do
69
+ class Baz2
70
+ def initialize(attributes)
71
+ end
72
+ end
73
+
74
+ class Qiz2 < Baz2
75
+ include Eventable
76
+ end
77
+ expect{q = Qiz2.new('blah')}.should_not raise_error
78
+ end
79
+
80
+ it "should pass along blocks if given" do
81
+ class Baz3
82
+ def initialize(attributes = nil, &block)
83
+ yield if block_given?
84
+ end
85
+ end
86
+
87
+ class Qiz3 < Baz3
88
+ include Eventable
89
+ end
90
+ random_value = rand(9999999999)
91
+ Qiz3.new() { @cheesy = random_value }
92
+ @cheesy.should == random_value
93
+ remove_instance_variable :@cheesy
94
+ end
95
+
96
+ end
97
+
53
98
  end
54
99
 
55
100
  context "when specifiying an event" do
@@ -431,4 +476,3 @@ class AnotherListenClass
431
476
  end
432
477
  end
433
478
 
434
-
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: eventable
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.3
5
+ version: 0.1.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mike Bethany
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-29 00:00:00 Z
13
+ date: 2011-07-06 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec