event_object 0.9.2 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e73347f0743cee6ad8f9e61bde232ce90508b15
4
- data.tar.gz: 030aab40ae2016c25031ab3e7136e384b0e9f67b
3
+ metadata.gz: e81c485937d85b0c9cd88b13cac0567f4aa0e03f
4
+ data.tar.gz: 7ce74e45fd9f99329ffb8db70cf1c1852027307a
5
5
  SHA512:
6
- metadata.gz: 170c391c95445cf10d497356ec4c3c0a71a1f395e1994c0ce19d21fed8d9ba6173b5227e35877319bd3165cbeffc23508ff1a12e4446e911b89ca508d1ece80b
7
- data.tar.gz: c177bb1525cedb2eb5e7398372e86601e50d7bc38eae0b3c1eeca0836347c91ed6ec596bb7d964a5fd46eaca893e0d37ea2807c7b06cdd16d6cbd972b4efba3d
6
+ metadata.gz: 76a40e1cdc625aea5a08916da033eb5cc600a2b0255f9f1d84914baf57263e0fa6b0beb2c61e641d80ade7469ab5c2027f5de70d25da3e6d1a1140868b4a56bf
7
+ data.tar.gz: 2956ba950da83365cef180a7788e02b6eeb0ffa93003dcb7a8b97cc144bdbf21043c42728cb1011d80e97a78d7d471dd6a828d2e3c47632af6c21e554f65a1d7
@@ -5,6 +5,11 @@ module EventObject
5
5
  dup.collect { |h| h.call(*a, &b) }
6
6
  end
7
7
 
8
+ # run events consecutive
9
+ def chain(a)
10
+ dup.inject(a) { |a, c| c.call(a) }
11
+ end
12
+
8
13
  def fire_for(t, *a)
9
14
  dup.collect { |h| t.instance_exec(*a, &h) }
10
15
  end
@@ -1,7 +1,7 @@
1
1
  module EventObject
2
2
  refine Object do
3
3
  def def(method, &b)
4
- define_method method, &b
4
+ define_singleton_method method, &b
5
5
  end
6
6
 
7
7
  def var(name, init=nil)
@@ -1,3 +1,3 @@
1
1
  module EventObject
2
- VERSION = "0.9.2"
2
+ VERSION = "0.9.4"
3
3
  end
@@ -4,7 +4,7 @@ describe EventObject do
4
4
  using EventObject
5
5
 
6
6
  class EventEmitter
7
- events :success, :error
7
+ events :success, :error, :data
8
8
  end
9
9
 
10
10
  class ParentObject
@@ -83,4 +83,28 @@ describe EventObject do
83
83
  obj.stop_listen(emitter, :success)
84
84
  expect(emitter.success!).to be_empty
85
85
  end
86
+
87
+ it "events chain" do
88
+ emitter = EventEmitter.new
89
+ emitter.on :data do |chunk|
90
+ chunk + " world"
91
+ end
92
+ emitter.on :data do |chunk|
93
+ chunk + "!!!"
94
+ end
95
+
96
+ data = emitter.data.chain('Hello')
97
+
98
+ expect(data).to eq('Hello world!!!')
99
+ end
100
+
101
+ it "define singleton method" do
102
+ expect {
103
+ object = Object.new
104
+ object.def :foo do
105
+ 1
106
+ end
107
+ expect(object.foo).to be 1
108
+ }.to_not raise_error
109
+ end
86
110
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - che
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-21 00:00:00.000000000 Z
11
+ date: 2015-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler