event_emitter 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -1
- data/Gemfile +0 -1
- data/History.txt +4 -0
- data/README.md +6 -0
- data/Rakefile +6 -0
- data/benchmark/benchmark.rb +57 -0
- data/benchmark/benchmark_helper.rb +22 -0
- data/event_emitter.gemspec +4 -0
- data/lib/event_emitter/emitter.rb +3 -2
- data/lib/event_emitter/version.rb +1 -1
- metadata +52 -10
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 53437cd7c3a975110a854e702cac7d66feafc6e2
|
4
|
+
data.tar.gz: 8902288ec0d61444c5f314273dfc1d6a621edae6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f7a1a1db775417a9549edb3e0a2a63744a0efee4de8e553a45deeb79b92afa2217ac38f3b6cb3ab3541587d6b7aedd207d4298f9867c2bdb8e282c3dc01f7845
|
7
|
+
data.tar.gz: 716573b4a20b33ef08e778536c76bc8dcb9e382dcd12d1a01ec5b90a1de364c1a1ff045de26affc414eff4f13473b4dbeaf768c1b147d88bede2d83bf25b430f
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/History.txt
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require File.expand_path 'benchmark_helper', File.dirname(__FILE__)
|
3
|
+
|
4
|
+
class Bench
|
5
|
+
|
6
|
+
class Foo
|
7
|
+
include EventEmitter
|
8
|
+
end
|
9
|
+
|
10
|
+
def bench_1on_100Kemit
|
11
|
+
foo = Foo.new
|
12
|
+
count = 0
|
13
|
+
foo.on :bar do |num|
|
14
|
+
count += num
|
15
|
+
end
|
16
|
+
100000.times do
|
17
|
+
foo.emit :bar, 1
|
18
|
+
end
|
19
|
+
raise Error, "test code error" unless count == 100000
|
20
|
+
end
|
21
|
+
|
22
|
+
def bench_1Kon_1Kemit
|
23
|
+
foo = Foo.new
|
24
|
+
count = 0
|
25
|
+
(1000-1).times do
|
26
|
+
foo.on :bar do
|
27
|
+
end
|
28
|
+
end
|
29
|
+
foo.on :bar do |num|
|
30
|
+
count += num
|
31
|
+
end
|
32
|
+
1000.times do
|
33
|
+
foo.emit :bar, 1
|
34
|
+
end
|
35
|
+
raise Error, "test code error" unless count == 1000
|
36
|
+
end
|
37
|
+
|
38
|
+
def bench_100Kon_1emit
|
39
|
+
foo = Foo.new
|
40
|
+
count = 0
|
41
|
+
1.upto(100000-1).each do |i|
|
42
|
+
foo.on "bar_#{i}" do
|
43
|
+
end
|
44
|
+
end
|
45
|
+
foo.on :bar do |num|
|
46
|
+
count += num
|
47
|
+
end
|
48
|
+
foo.emit :bar, 1
|
49
|
+
raise Error, "test code error" unless count == 1
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
if __FILE__ == $0
|
56
|
+
Bench.run
|
57
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
$:.unshift File.expand_path '../lib', File.dirname(__FILE__)
|
2
|
+
require 'event_emitter'
|
3
|
+
require 'benchmark'
|
4
|
+
|
5
|
+
class Bench
|
6
|
+
|
7
|
+
class Error < StandardError
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.run
|
11
|
+
puts "ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
12
|
+
bench = self.new
|
13
|
+
Benchmark.bm do |x|
|
14
|
+
bench.methods.select{|i| i.to_s =~ /^bench_(.+)$/}.sort.each do |m|
|
15
|
+
x.report m.to_s.scan(/^bench_(.+)$/)[0][0] do
|
16
|
+
bench.__send__ m
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/event_emitter.gemspec
CHANGED
@@ -15,4 +15,8 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
16
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
17
|
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.add_development_dependency "minitest"
|
20
|
+
gem.add_development_dependency "rake"
|
21
|
+
gem.add_development_dependency "bundler", "~> 1.3"
|
18
22
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
module EventEmitter
|
3
3
|
def self.included(klass)
|
4
|
-
klass.extend ClassMethods
|
4
|
+
# klass.extend ClassMethods
|
5
5
|
klass.__send__ :include, InstanceMethods
|
6
6
|
end
|
7
7
|
|
@@ -44,9 +44,10 @@ module EventEmitter
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def emit(type, *data)
|
47
|
+
type = type.to_sym
|
47
48
|
__events.each do |e|
|
48
49
|
case e[:type]
|
49
|
-
when type
|
50
|
+
when type
|
50
51
|
listener = e[:listener]
|
51
52
|
e[:type] = nil if e[:params][:once]
|
52
53
|
instance_exec(*data, &listener)
|
metadata
CHANGED
@@ -1,16 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: event_emitter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Sho Hashimoto
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
13
|
-
dependencies:
|
11
|
+
date: 2013-03-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
14
55
|
description: Ruby port of EventEmitter from Node.js
|
15
56
|
email:
|
16
57
|
- hashimoto@shokai.org
|
@@ -24,6 +65,8 @@ files:
|
|
24
65
|
- LICENSE.txt
|
25
66
|
- README.md
|
26
67
|
- Rakefile
|
68
|
+
- benchmark/benchmark.rb
|
69
|
+
- benchmark/benchmark_helper.rb
|
27
70
|
- event_emitter.gemspec
|
28
71
|
- lib/event_emitter.rb
|
29
72
|
- lib/event_emitter/emitter.rb
|
@@ -39,27 +82,26 @@ files:
|
|
39
82
|
- test/test_singular_method.rb
|
40
83
|
homepage: http://shokai.github.com/event_emitter
|
41
84
|
licenses: []
|
85
|
+
metadata: {}
|
42
86
|
post_install_message:
|
43
87
|
rdoc_options: []
|
44
88
|
require_paths:
|
45
89
|
- lib
|
46
90
|
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
-
none: false
|
48
91
|
requirements:
|
49
|
-
- -
|
92
|
+
- - '>='
|
50
93
|
- !ruby/object:Gem::Version
|
51
94
|
version: '0'
|
52
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
54
96
|
requirements:
|
55
|
-
- -
|
97
|
+
- - '>='
|
56
98
|
- !ruby/object:Gem::Version
|
57
99
|
version: '0'
|
58
100
|
requirements: []
|
59
101
|
rubyforge_project:
|
60
|
-
rubygems_version:
|
102
|
+
rubygems_version: 2.0.3
|
61
103
|
signing_key:
|
62
|
-
specification_version:
|
104
|
+
specification_version: 4
|
63
105
|
summary: Ruby port of EventEmitter from Node.js
|
64
106
|
test_files:
|
65
107
|
- test/test_catch_all_events.rb
|