event_emitter 0.0.7 → 0.1.0

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
+ === 0.1.0 2012-11-15
2
+
3
+ * support on/emit multiple arguments
4
+
1
5
  === 0.0.7 2012-11-09
2
6
 
3
7
  * on/emit without any args
data/README.rdoc CHANGED
@@ -45,14 +45,14 @@ call event
45
45
 
46
46
  regist event using "once"
47
47
 
48
- user.once :eat do |data|
49
- puts "#{name} -> #{data}"
48
+ user.once :eat do |what, where|
49
+ puts "#{name} -> eat #{what} at #{where}"
50
50
  end
51
51
 
52
52
  call
53
53
 
54
- user.emit :eat, "BEEF" # => "shokai -> BEEF"
55
- user.emit :eat, "Ramen" # => do not call. call only first time.
54
+ user.emit :eat, "BEEF", "zanmai" # => "shokai -> eat BEEF at zanmai"
55
+ user.emit :eat, "Ramen", "marutomo" # => do not call. call only first time.
56
56
 
57
57
  apply as instance-specific method
58
58
 
@@ -43,12 +43,12 @@ module EventEmitter
43
43
  end
44
44
  end
45
45
 
46
- def emit(type, data=nil)
46
+ def emit(type, *data)
47
47
  events.each do |e|
48
48
  if e[:type] == type.to_sym
49
49
  listener = e[:listener]
50
50
  remove_listener e[:id] if e[:params][:once]
51
- instance_exec(data, &listener)
51
+ instance_exec(*data, &listener)
52
52
  end
53
53
  end
54
54
  end
data/lib/event_emitter.rb CHANGED
@@ -4,5 +4,5 @@ $:.unshift(File.dirname(__FILE__)) unless
4
4
  require 'event_emitter/emitter'
5
5
 
6
6
  module EventEmitter
7
- VERSION = '0.0.7'
7
+ VERSION = '0.1.0'
8
8
  end
data/samples/sample.rb CHANGED
@@ -25,9 +25,9 @@ shokai.emit :go, {:place => 'mountain'}
25
25
  ymrl.emit :go, :place => 'cyberspace'
26
26
 
27
27
 
28
- shokai.once :eat do |data|
29
- puts "#{name} -> #{data}"
28
+ shokai.once :eat do |what, where|
29
+ puts "#{name} -> #{what} at #{where}"
30
30
  end
31
31
 
32
- shokai.emit :eat, 'BEEF'
33
- shokai.emit :eat, 'Ramen' # do not call. call only first time if regist with "once"
32
+ shokai.emit :eat, 'BEEF', 'zanmai'
33
+ shokai.emit :eat, 'Ramen', 'marutomo' # do not call. call only first time if regist with "once"
@@ -41,6 +41,27 @@ class TestClassMethod < MiniTest::Unit::TestCase
41
41
  assert created_at == @now, 'instance method'
42
42
  end
43
43
 
44
+ def test_on_emit_multiargs
45
+ _user = nil
46
+ _message = nil
47
+ _session = nil
48
+ created_at = nil
49
+ Foo.on :chat2 do |user, message, session|
50
+ _user = user
51
+ _message = message
52
+ _session = session
53
+ created_at = self.created_at
54
+ end
55
+
56
+ sid = Time.now.to_i
57
+ Foo.emit :chat2, 'shokai', 'hello world', sid
58
+
59
+ assert _user == 'shokai'
60
+ assert _message == 'hello world'
61
+ assert _session == sid
62
+ assert created_at == @now, 'instance method'
63
+ end
64
+
44
65
  def test_add_listener
45
66
  result = nil
46
67
  created_at = nil
@@ -37,6 +37,27 @@ class TestEventEmitter < MiniTest::Unit::TestCase
37
37
  assert created_at == @now, 'instance method'
38
38
  end
39
39
 
40
+ def test_on_emit_multiargs
41
+ _user = nil
42
+ _message = nil
43
+ _session = nil
44
+ created_at = nil
45
+ @foo.on :chat do |user, message, session|
46
+ _user = user
47
+ _message = message
48
+ _session = session
49
+ created_at = self.created_at
50
+ end
51
+
52
+ sid = Time.now.to_i
53
+ @foo.emit :chat, 'shokai', 'hello world', sid
54
+
55
+ assert _user == 'shokai'
56
+ assert _message == 'hello world'
57
+ assert _session == sid
58
+ assert created_at == @now, 'instance method'
59
+ end
60
+
40
61
  def test_add_listener
41
62
  result = nil
42
63
  created_at = nil
@@ -37,6 +37,27 @@ class TestSingularMethod < MiniTest::Unit::TestCase
37
37
  assert created_at == @now, 'instance method'
38
38
  end
39
39
 
40
+ def test_on_emit_multiargs
41
+ _user = nil
42
+ _message = nil
43
+ _session = nil
44
+ created_at = nil
45
+ @foo.on :chat do |user, message, session|
46
+ _user = user
47
+ _message = message
48
+ _session = session
49
+ created_at = self.created_at
50
+ end
51
+
52
+ sid = Time.now.to_i
53
+ @foo.emit :chat, 'shokai', 'hello world', sid
54
+
55
+ assert _user == 'shokai'
56
+ assert _message == 'hello world'
57
+ assert _session == sid
58
+ assert created_at == @now, 'instance method'
59
+ end
60
+
40
61
  def test_add_listener
41
62
  result = nil
42
63
  created_at = nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_emitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-08 00:00:00.000000000 Z
12
+ date: 2012-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  segments:
108
108
  - 0
109
- hash: -3918695079194691329
109
+ hash: -4020786743775049336
110
110
  required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  none: false
112
112
  requirements: