event_emitter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ *~
3
+ pkg/*
4
+ .\#*
5
+ *\#*
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem 'hoe'
4
+ gem 'newgem'
5
+ gem 'minitest'
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ RedCloth (4.2.9)
5
+ activesupport (2.3.14)
6
+ hoe (3.1.1)
7
+ rake (~> 0.8)
8
+ minitest (4.2.0)
9
+ newgem (1.5.3)
10
+ RedCloth (>= 4.1.1)
11
+ activesupport (~> 2.3.4)
12
+ hoe (>= 2.4.0)
13
+ rubigen (>= 1.5.3)
14
+ syntax (>= 1.0.0)
15
+ rake (0.9.2.2)
16
+ rubigen (1.5.8)
17
+ activesupport (>= 2.3.5, < 3.2.0)
18
+ syntax (1.0.0)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ hoe
25
+ minitest
26
+ newgem
data/History.txt ADDED
@@ -0,0 +1,3 @@
1
+ === 0.0.1 2012-11-07
2
+
3
+ * implement "on" and "emit"
data/Manifest.txt ADDED
@@ -0,0 +1,15 @@
1
+ .gitignore
2
+ Gemfile
3
+ Gemfile.lock
4
+ History.txt
5
+ Manifest.txt
6
+ README.rdoc
7
+ Rakefile
8
+ lib/event_emitter.rb
9
+ lib/event_emitter/emitter.rb
10
+ samples/sample.rb
11
+ script/console
12
+ script/destroy
13
+ script/generate
14
+ test/test_event_emitter.rb
15
+ test/test_helper.rb
data/README.rdoc ADDED
@@ -0,0 +1,58 @@
1
+ = event_emitter
2
+
3
+ * http://github.com/shokai/event_emitter
4
+
5
+ == INSTALL:
6
+
7
+ * gem install event_emitter
8
+
9
+ == DESCRIPTION:
10
+
11
+ Ruby port of EventEmitter from Node.js
12
+
13
+ == SYNOPSIS:
14
+
15
+ require 'event_emitter'
16
+
17
+ include
18
+
19
+ class Foo
20
+ include EventEmitter
21
+ end
22
+
23
+ regist event listener
24
+
25
+ foo = Foo.new
26
+ foo.on :chat do |data|
27
+ puts "chat - #{data[:user]} : #{data[:message]}"
28
+ end
29
+
30
+ call event
31
+
32
+ foo.emit :chat, {:user => 'shokai', :message => 'hello!!'}
33
+ # => chat - shokai : hello!!
34
+
35
+ == LICENSE:
36
+
37
+ (The MIT License)
38
+
39
+ Copyright (c) 2012 Sho Hashimoto
40
+
41
+ Permission is hereby granted, free of charge, to any person obtaining
42
+ a copy of this software and associated documentation files (the
43
+ 'Software'), to deal in the Software without restriction, including
44
+ without limitation the rights to use, copy, modify, merge, publish,
45
+ distribute, sublicense, and/or sell copies of the Software, and to
46
+ permit persons to whom the Software is furnished to do so, subject to
47
+ the following conditions:
48
+
49
+ The above copyright notice and this permission notice shall be
50
+ included in all copies or substantial portions of the Software.
51
+
52
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
53
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
54
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
55
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
56
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
57
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
58
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/event_emitter'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'event_emitter' do
14
+ self.developer 'Sho Hashimoto', 'hashimoto@shokai.org'
15
+ self.rubyforge_name = self.name # TODO this is default value
16
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
17
+
18
+ end
19
+
20
+ require 'newgem/tasks'
21
+ Dir['tasks/**/*.rake'].each { |t| load t }
22
+
23
+ # TODO - want other tests/tasks run by default? Add them to the list
24
+ # remove_task :default
25
+ # task :default => [:spec, :features]
@@ -0,0 +1,28 @@
1
+
2
+ module EventEmitter
3
+ def self.included(klass)
4
+ klass.extend ClassMethods
5
+ klass.__send__ :include, InstanceMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ end
10
+
11
+ module InstanceMethods
12
+ def events
13
+ @events ||= []
14
+ end
15
+
16
+ def on(type, &block)
17
+ raise ArgumentError, 'listener block not given' unless block_given?
18
+ events << {:type => type.to_sym, :listener => block}
19
+ end
20
+
21
+ def emit(type, data)
22
+ events.each do |e|
23
+ e[:listener].call data if e[:type] == type.to_sym
24
+ end
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,8 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'event_emitter/emitter'
5
+
6
+ module EventEmitter
7
+ VERSION = '0.0.1'
8
+ end
data/samples/sample.rb ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
3
+ require 'event_emitter'
4
+
5
+ class Foo
6
+ include EventEmitter
7
+ end
8
+
9
+ foo = Foo.new
10
+
11
+ foo.on 'chat' do |data|
12
+ puts "chat - #{data[:user]} : #{data[:message]}"
13
+ end
14
+
15
+ foo.on 'sum' do |data|
16
+ puts data.inject{|a,b|
17
+ a+b
18
+ }
19
+ end
20
+
21
+ foo.emit 'chat', {:user => 'shokai', :message => 'hello world'}
22
+ foo.emit :chat, :user => 'ymrl', :message => 'hello work'
23
+
24
+ foo.emit 'sum', [1,2,3,45]
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/event_emitter.rb'}"
9
+ puts "Loading event_emitter gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,25 @@
1
+ require File.expand_path 'test_helper', File.dirname(__FILE__)
2
+
3
+ class TestEventEmitter < MiniTest::Unit::TestCase
4
+
5
+ class Foo
6
+ include EventEmitter
7
+ end
8
+
9
+ def setup
10
+ @foo = Foo.new
11
+ end
12
+
13
+ def test_on_emit
14
+ result = nil
15
+ @foo.on :chat do |data|
16
+ puts "chat - #{data[:user]} : #{data[:message]}"
17
+ result = data
18
+ end
19
+
20
+ @foo.emit :chat, :user => 'shokai', :message => 'hello world'
21
+
22
+ assert result[:user] == 'shokai'
23
+ assert result[:message] == 'hello world'
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'minitest/autorun'
3
+
4
+ $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
5
+ require 'event_emitter'
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: event_emitter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sho Hashimoto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rdoc
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.10'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.10'
30
+ - !ruby/object:Gem::Dependency
31
+ name: newgem
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.5.3
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.5.3
46
+ - !ruby/object:Gem::Dependency
47
+ name: hoe
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.1'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ description: Ruby port of EventEmitter from Node.js
63
+ email:
64
+ - hashimoto@shokai.org
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files:
68
+ - History.txt
69
+ - Manifest.txt
70
+ - README.rdoc
71
+ files:
72
+ - .gitignore
73
+ - Gemfile
74
+ - Gemfile.lock
75
+ - History.txt
76
+ - Manifest.txt
77
+ - README.rdoc
78
+ - Rakefile
79
+ - lib/event_emitter.rb
80
+ - lib/event_emitter/emitter.rb
81
+ - samples/sample.rb
82
+ - script/console
83
+ - script/destroy
84
+ - script/generate
85
+ - test/test_event_emitter.rb
86
+ - test/test_helper.rb
87
+ - .gemtest
88
+ homepage: http://github.com/shokai/event_emitter
89
+ licenses: []
90
+ post_install_message:
91
+ rdoc_options:
92
+ - --main
93
+ - README.rdoc
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ segments:
103
+ - 0
104
+ hash: 4410593862136715009
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project: event_emitter
113
+ rubygems_version: 1.8.24
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: Ruby port of EventEmitter from Node.js
117
+ test_files:
118
+ - test/test_event_emitter.rb
119
+ - test/test_helper.rb