eventable 0.1.4 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6a0096af61ceb5610845b10b6610df58bace5bd6
4
+ data.tar.gz: 793ba15120801ec32fe9a463e53938709a82edfc
5
+ SHA512:
6
+ metadata.gz: 0dd5d6332c1b01e88777d19669bfdcad44fdc790ed6fb79c4c47256a973b346c741c697dcc271eb4e471d3a4f525f070a80b82630d2ef052b66314291acdc123
7
+ data.tar.gz: 4c33b803d21e1a7f5df891d86827f8cfcd3b5116d8334fdf298a268266d096d8bf6fee317ba25a8c39b66582e2c3129615877be2e81973bf25fa99dc9ec08471
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
+ /example
2
3
  .bundle
3
4
  Gemfile.lock
4
5
  pkg/*
data/Gemfile CHANGED
File without changes
File without changes
@@ -170,6 +170,20 @@ This example shows you how you might actually use it in a multi-threaded environ
170
170
 
171
171
  ##Version History##
172
172
 
173
+ **2014.09.10**
174
+ Ver: 0.2.1
175
+
176
+ * Verified to work with Ruby 2.1
177
+ * Updated specs to RSpec 2.99
178
+ * Updated dependencies and author links.
179
+
180
+ **2014.03.26**
181
+ Ver: 0.2.0
182
+
183
+ Updates:
184
+
185
+ Updating for Ruby 2.x
186
+
173
187
  **2011.07.05**
174
188
  Ver: 0.1.4
175
189
 
data/Rakefile CHANGED
File without changes
File without changes
@@ -1,8 +1,5 @@
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
3
 
7
4
  require "rubygems"
8
5
  require "eventable/version"
@@ -11,16 +8,16 @@ Gem::Specification.new do |s|
11
8
  s.name = "eventable"
12
9
  s.version = Eventable::VERSION
13
10
  s.authors = ["Mike Bethany"]
14
- s.email = ["mikbe.tk@gmail.com"]
15
- s.homepage = "http://mikbe.tk/projects#eventable"
11
+ s.email = ["mike@mikebethany.com"]
12
+ s.homepage = "http://mikebethany.com"
16
13
  s.summary = %q{An incredibly simple and easy to use event mixin module.}
17
14
  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 this is the solution for you.}
18
15
  s.license = 'MIT'
19
16
 
20
17
  s.required_ruby_version = ">= 1.9.2"
21
18
 
22
- s.add_development_dependency('rspec', "~>2.6")
23
- s.add_development_dependency('bundler', "~>1.0")
19
+ s.add_development_dependency('rspec', "~>2.99")
20
+ s.add_development_dependency('bundler', "~>1.6")
24
21
 
25
22
  s.files = `git ls-files`.split("\n")
26
23
  s.test_files = `git ls-files -- {spec}/*`.split("\n")
File without changes
File without changes
File without changes
@@ -1,3 +1,3 @@
1
1
  module Eventable
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -62,7 +62,7 @@ describe Eventable do
62
62
  include Eventable
63
63
  end
64
64
 
65
- expect{q = Qiz.new}.should_not raise_error
65
+ expect{q = Qiz.new}.not_to raise_error
66
66
  end
67
67
 
68
68
  it "should not raise an error if they are required and given" do
@@ -74,7 +74,7 @@ describe Eventable do
74
74
  class Qiz2 < Baz2
75
75
  include Eventable
76
76
  end
77
- expect{q = Qiz2.new('blah')}.should_not raise_error
77
+ expect{q = Qiz2.new('blah')}.not_to raise_error
78
78
  end
79
79
 
80
80
  it "should pass along blocks if given" do
@@ -205,8 +205,8 @@ describe Eventable do
205
205
  @evented.register_for_event(event: :stuff_happens, listener: @listener, callback: :callback2)
206
206
  @evented.do_event
207
207
  sleep(CALLBACK_WAIT)
208
- @listener.callback?.should be_true
209
- @listener.callback2?.should be_true
208
+ @listener.callback?.should be true
209
+ @listener.callback2?.should be true
210
210
  end
211
211
 
212
212
  it "should allow callbacks to class methods" do
@@ -214,7 +214,7 @@ describe Eventable do
214
214
  @evented.register_for_event(event: :stuff_happens, listener: ListenClass, callback: :class_callback)
215
215
  @evented.do_event
216
216
  sleep(CALLBACK_WAIT)
217
- ListenClass.class_callback?.should be_true
217
+ ListenClass.class_callback?.should be true
218
218
  end
219
219
 
220
220
  context "when multiple classes mixin eventable" do
@@ -228,8 +228,8 @@ describe Eventable do
228
228
  another_evented.register_for_event(event: :stuff_happens, listener: another_listener, callback: :callback)
229
229
  @evented.do_event
230
230
  sleep(CALLBACK_WAIT)
231
- @listener.callback?.should be_true
232
- another_listener.callback?.should_not be_true
231
+ @listener.callback?.should be true
232
+ another_listener.callback?.should_not be true
233
233
  end
234
234
 
235
235
  it "should not call the wrong class when both evented classes fire events" do
@@ -240,8 +240,8 @@ describe Eventable do
240
240
  @evented.do_event
241
241
  another_evented.do_event
242
242
  sleep(CALLBACK_WAIT)
243
- @listener.callback?.should be_true
244
- another_listener.callback2?.should be_true
243
+ @listener.callback?.should be true
244
+ another_listener.callback2?.should be true
245
245
  end
246
246
 
247
247
  end
@@ -266,7 +266,7 @@ describe Eventable do
266
266
  @evented.register_for_event(event: :stuff_happens, listener: @listener, callback: :callback)
267
267
  @evented.unregister_for_event(event: :stuff_happens, listener: @listener, callback: :callback)
268
268
  @evented.do_event
269
- @listener.callback?.should_not be_true
269
+ @listener.callback?.should_not be true
270
270
  end
271
271
 
272
272
  it "should automatically remove callbacks to objects that are garbage collected" do
@@ -286,12 +286,12 @@ describe Eventable do
286
286
 
287
287
  it "should return false if the event did not fire" do
288
288
  @evented.do_event
289
- @evented.do_event.should be_false
289
+ @evented.do_event.should be false
290
290
  end
291
291
 
292
292
  it "should return true if the event did fire" do
293
293
  @evented.register_for_event(event: :stuff_happens, listener: @listener, callback: :callback)
294
- @evented.do_event.should be_true
294
+ @evented.do_event.should be true
295
295
  end
296
296
 
297
297
  it "should not throw an error if no listeners have been registered for an event" do
@@ -303,13 +303,13 @@ describe Eventable do
303
303
  @evented.register_for_event(event: :stuff_happens, listener: @listener, callback: :callback)
304
304
  @evented.do_event
305
305
  sleep(CALLBACK_WAIT)
306
- @listener.callback?.should be_true
306
+ @listener.callback?.should be true
307
307
  end
308
308
 
309
309
  it "should not call back the wrong method when the event is fired" do
310
310
  @evented.register_for_event(event: :stuff_happens, listener: @listener, callback: :callback)
311
311
  @evented.do_event
312
- @listener.callback2?.should_not be_true
312
+ @listener.callback2?.should_not be true
313
313
  end
314
314
 
315
315
  it "should call back more than one class" do
@@ -320,8 +320,8 @@ describe Eventable do
320
320
 
321
321
  @evented.do_event
322
322
  sleep(CALLBACK_WAIT)
323
- @listener.callback?.should be_true
324
- listener2.callback2?.should be_true
323
+ @listener.callback?.should be true
324
+ listener2.callback2?.should be true
325
325
  end
326
326
 
327
327
  it "should not call back the wrong method when using multiple classes" do
@@ -332,8 +332,8 @@ describe Eventable do
332
332
 
333
333
  @evented.do_event
334
334
  sleep(CALLBACK_WAIT)
335
- @listener.callback2?.should_not be_true
336
- listener2.callback?.should_not be_true
335
+ @listener.callback2?.should_not be true
336
+ listener2.callback?.should_not be true
337
337
  end
338
338
 
339
339
  context "and it has return data" do
File without changes
metadata CHANGED
@@ -1,96 +1,86 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: eventable
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.1.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - Mike Bethany
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
-
13
- date: 2011-07-06 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
11
+ date: 2014-09-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
16
14
  name: rspec
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ~>
22
- - !ruby/object:Gem::Version
23
- version: "2.6"
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.99'
24
20
  type: :development
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: bundler
28
21
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
30
- none: false
31
- requirements:
32
- - - ~>
33
- - !ruby/object:Gem::Version
34
- version: "1.0"
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.99'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
35
34
  type: :development
36
- version_requirements: *id002
37
- description: Provides an easy to use and understand event model. If you want a simple, light-weight way to add events to your classes this is the solution for you.
38
- email:
39
- - mikbe.tk@gmail.com
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ description: Provides an easy to use and understand event model. If you want a simple,
42
+ light-weight way to add events to your classes this is the solution for you.
43
+ email:
44
+ - mike@mikebethany.com
40
45
  executables: []
41
-
42
46
  extensions: []
43
-
44
47
  extra_rdoc_files: []
45
-
46
- files:
47
- - .DS_Store
48
- - .gitignore
48
+ files:
49
+ - ".gitignore"
49
50
  - Gemfile
50
51
  - LICENSE.txt
51
52
  - README.markdown
52
53
  - Rakefile
53
54
  - autotest/discover.rb
54
55
  - eventable.gemspec
55
- - example/example.rb
56
- - example/example_output.txt
57
- - example/simple_example.rb
58
- - example/simple_output.txt
59
- - lib/.DS_Store
60
56
  - lib/eventable.rb
61
57
  - lib/eventable/errors.rb
62
58
  - lib/eventable/eventable.rb
63
59
  - lib/eventable/version.rb
64
- - spec/.DS_Store
65
60
  - spec/eventable/eventable_spec.rb
66
61
  - spec/spec_helper.rb
67
- - vendor/.DS_Store
68
- homepage: http://mikbe.tk/projects#eventable
69
- licenses:
62
+ homepage: http://mikebethany.com
63
+ licenses:
70
64
  - MIT
65
+ metadata: {}
71
66
  post_install_message:
72
67
  rdoc_options: []
73
-
74
- require_paths:
68
+ require_paths:
75
69
  - lib
76
- required_ruby_version: !ruby/object:Gem::Requirement
77
- none: false
78
- requirements:
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
79
72
  - - ">="
80
- - !ruby/object:Gem::Version
73
+ - !ruby/object:Gem::Version
81
74
  version: 1.9.2
82
- required_rubygems_version: !ruby/object:Gem::Requirement
83
- none: false
84
- requirements:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
85
77
  - - ">="
86
- - !ruby/object:Gem::Version
87
- version: "0"
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
88
80
  requirements: []
89
-
90
81
  rubyforge_project:
91
- rubygems_version: 1.8.5
82
+ rubygems_version: 2.2.2
92
83
  signing_key:
93
- specification_version: 3
84
+ specification_version: 4
94
85
  summary: An incredibly simple and easy to use event mixin module.
95
86
  test_files: []
96
-
data/.DS_Store DELETED
Binary file
@@ -1,82 +0,0 @@
1
- $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "/../lib"))
2
- require 'eventable'
3
-
4
- class EventedClass
5
- include Eventable
6
- event :stuff_happens
7
- event :other_stuff_happens
8
-
9
- def initialize
10
- # If you don't call super Eventable will raise an error
11
- super # <= VERY important, comment this out to see the error
12
- # do your initialize stuff
13
- end
14
-
15
- def make_stuff_happen(parent_id)
16
- # You handle concurrency however you want, threads or fibers, up to you.
17
- Thread.new{
18
- puts "firing :stuff_happens"
19
- fire_event(:stuff_happens, {:parent_id=>parent_id, :some_value => rand(1000)})
20
- }
21
- end
22
-
23
- def start_other_stuff_happening
24
- Thread.new {
25
- 5.times do
26
- sleep(rand(1)+2)
27
- puts "firing :other_stuff_happens"
28
- fire_event(:other_stuff_happens)
29
- end
30
- }
31
- end
32
-
33
- end
34
-
35
- class ListenerClass
36
-
37
- def initialize(some_object)
38
- @some_thing = some_object
39
- @some_thing.register_for_event(event: :stuff_happens, listener: self, callback: :stuff_happened)
40
- end
41
-
42
- def do_somestuff(parent_id, times=6)
43
- # I wrapped this in a thread to show it works cross threaded
44
- Thread.new{
45
- id = rand(1000)
46
- times.times do
47
- sleep(rand(2)+1)
48
- puts "[#{parent_id}, #{id}]: do_somestuff"
49
- @some_thing.make_stuff_happen(parent_id)
50
- end
51
- }
52
- end
53
-
54
- def stuff_happened(stuff)
55
- splat = stuff
56
- puts "[#{splat[:parent_id]}] stuff_happened callback: #{splat[:some_value]}"
57
- end
58
-
59
- def other_stuff_happened
60
- puts "[n/a] same_stuff_happened callback: n/a"
61
- end
62
-
63
- end
64
-
65
- # Now show it running
66
- evented = EventedClass.new
67
-
68
- # You can inject the evented class
69
- listener = ListenerClass.new(evented)
70
-
71
- # or attach to events outside of a listener class
72
- evented.register_for_event(event: :other_stuff_happens, listener: listener, callback: :other_stuff_happened)
73
-
74
- evented.start_other_stuff_happening
75
- (1..3).each do |index|
76
- listener.do_somestuff(index)
77
- puts "[#{index}] did some stuff, sleeping"
78
- sleep(rand(3)+4)
79
- puts "[#{index}] slept"
80
- end
81
-
82
- puts "all done"
@@ -1,56 +0,0 @@
1
- [1] did some stuff, sleeping
2
- [1, 932]: do_somestuff
3
- firing :stuff_happens
4
- [1] stuff_happened callback: 824
5
- firing :other_stuff_happens
6
- [n/a] same_stuff_happened callback: n/a
7
- [1, 932]: do_somestuff
8
- firing :stuff_happens
9
- [1] stuff_happened callback: 407
10
- [1, 932]: do_somestuff
11
- firing :stuff_happens
12
- [1] stuff_happened callback: 841
13
- firing :other_stuff_happens
14
- [n/a] same_stuff_happened callback: n/a
15
- [1, 932]: do_somestuff
16
- firing :stuff_happens
17
- [1] stuff_happened callback: 779
18
- [1] slept
19
- [2] did some stuff, sleeping
20
- firing :other_stuff_happens
21
- [n/a] same_stuff_happened callback: n/a
22
- [1, 932]: do_somestuff
23
- firing :stuff_happens
24
- [1] stuff_happened callback: 252
25
- [2, 316]: do_somestuff
26
- firing :stuff_happens
27
- [2] stuff_happened callback: 174
28
- firing :other_stuff_happens
29
- [n/a] same_stuff_happened callback: n/a
30
- [2, 316]: do_somestuff
31
- firing :stuff_happens
32
- [2] stuff_happened callback: 193
33
- [1, 932]: do_somestuff
34
- firing :stuff_happens
35
- [1] stuff_happened callback: 535
36
- [2] slept
37
- [3] did some stuff, sleeping
38
- firing :other_stuff_happens
39
- [n/a] same_stuff_happened callback: n/a
40
- [2, 316]: do_somestuff
41
- firing :stuff_happens
42
- [2] stuff_happened callback: 420
43
- [3, 748]: do_somestuff
44
- firing :stuff_happens
45
- [3] stuff_happened callback: 545
46
- [2, 316]: do_somestuff
47
- firing :stuff_happens
48
- [2] stuff_happened callback: 471
49
- [3, 748]: do_somestuff
50
- firing :stuff_happens
51
- [2, 316]: do_somestuff
52
- [3] stuff_happened callback: 266
53
- firing :stuff_happens
54
- [2] stuff_happened callback: 481
55
- [3] slept
56
- all done
@@ -1,42 +0,0 @@
1
- $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "/../lib"))
2
- require 'eventable'
3
-
4
- class EventClass
5
- include Eventable
6
-
7
- # This is all you have to do to add an event (after you include Eventable)
8
- event :stuff_happens
9
-
10
- # don't name your method fire_event, that's taken
11
- def do_event
12
- puts "firing :stuff_happens"
13
- # And this is all you have to do to make the event happen
14
- fire_event(:stuff_happens, rand(1000))
15
- end
16
-
17
- end
18
-
19
- class ListenClass
20
-
21
- def stuff_happened(stuff)
22
- puts "stuff happened callback: #{stuff}"
23
- end
24
-
25
- end
26
-
27
- # Create an instance of a class that has an event
28
- evented = EventClass.new
29
-
30
- # Create a class that listens for that event
31
- listener = ListenClass.new
32
-
33
- # Register the listener with the instance that will have the event
34
- evented.register_for_event(event: :stuff_happens, listener: listener, callback: :stuff_happened)
35
-
36
- # We'll just arbitrarilly fire the event to see how it works
37
- evented.do_event
38
-
39
- # Wait just to be sure you see it happen
40
- sleep(1)
41
-
42
-
@@ -1,2 +0,0 @@
1
- firing :stuff_happens
2
- stuff happened callback: 454
Binary file
Binary file
Binary file