em-wrapper 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +26 -0
- data/LICENSE.txt +20 -0
- data/README.md +53 -0
- data/Rakefile +29 -0
- data/VERSION +1 -0
- data/lib/em-wrapper.rb +58 -0
- data/test +23 -0
- metadata +156 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
gem "object-proxy", ">= 0.3.0"
|
5
|
+
gem "hash-utils", ">= 0.17.0"
|
6
|
+
gem "eventmachine", ">= 0"
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "bundler", ">= 1.0.0"
|
12
|
+
gem "jeweler2", ">= 2.0.0"
|
13
|
+
gem "riot", ">= 0.12.3"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
eventmachine (0.12.10)
|
5
|
+
git (1.2.5)
|
6
|
+
hash-utils (2.0.0)
|
7
|
+
ruby-version
|
8
|
+
jeweler2 (2.0.9)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
object-proxy (0.3.0)
|
11
|
+
hash-utils (>= 0.12.1)
|
12
|
+
riot (0.12.5)
|
13
|
+
rr
|
14
|
+
rr (1.0.4)
|
15
|
+
ruby-version (0.3.1)
|
16
|
+
|
17
|
+
PLATFORMS
|
18
|
+
ruby
|
19
|
+
|
20
|
+
DEPENDENCIES
|
21
|
+
bundler (>= 1.0.0)
|
22
|
+
eventmachine
|
23
|
+
hash-utils (>= 0.17.0)
|
24
|
+
jeweler2 (>= 2.0.0)
|
25
|
+
object-proxy (>= 0.3.0)
|
26
|
+
riot (>= 0.12.3)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 - 2012 Martin Kozák (martinkozak@martinkozak.net)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
EventMachine Wrapper
|
2
|
+
====================
|
3
|
+
|
4
|
+
**em-wrapper** wraps objects callbacks to [EventMachine][8] next ticks using
|
5
|
+
`EM::next_tick`, so allows transparent multiplexing of objects which
|
6
|
+
aren't multiplexable by default.
|
7
|
+
|
8
|
+
It provides proxied class, so returned class is kind of the same class
|
9
|
+
as wrapped class, with different `#object_id` only. Also standard returns
|
10
|
+
work as expected and as is usuall.
|
11
|
+
|
12
|
+
See some example:
|
13
|
+
|
14
|
+
require "em-wrapper"
|
15
|
+
require "eventmachine"
|
16
|
+
|
17
|
+
class Foo
|
18
|
+
def foo
|
19
|
+
yield :foo
|
20
|
+
return :bar
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
wrapped = EM::Wrapper::new(Foo)::new
|
25
|
+
EM::run do
|
26
|
+
p wrapped.foo { |value| # 1. will print :bar out
|
27
|
+
p value # 2. will be run in next EM tick, will print :foo out
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
Also object wrapping is supported. In that case, simply give object instance
|
32
|
+
instead of class object to the constructor. Wrapped object instance will be returned.
|
33
|
+
|
34
|
+
Contributing
|
35
|
+
------------
|
36
|
+
|
37
|
+
1. Fork it.
|
38
|
+
2. Create a branch (`git checkout -b 20101220-my-change`).
|
39
|
+
3. Commit your changes (`git commit -am "Added something"`).
|
40
|
+
4. Push to the branch (`git push origin 20101220-my-change`).
|
41
|
+
5. Create an [Issue][9] with a link to your branch.
|
42
|
+
6. Enjoy a refreshing Diet Coke and wait.
|
43
|
+
|
44
|
+
|
45
|
+
Copyright
|
46
|
+
---------
|
47
|
+
|
48
|
+
Copyright © 2011 [Martin Kozák][10]. See `LICENSE.txt` for
|
49
|
+
further details.
|
50
|
+
|
51
|
+
[8]: http://rubyeventmachine.com/
|
52
|
+
[9]: http://github.com/martinkozak/em-wrapper/issues
|
53
|
+
[10]: http://www.martinkozak.net/
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'rake'
|
14
|
+
require 'jeweler2'
|
15
|
+
|
16
|
+
Jeweler::Tasks.new do |gem|
|
17
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
18
|
+
gem.name = "em-wrapper"
|
19
|
+
gem.homepage = "http://github.com/martinkozak/em-wrapper"
|
20
|
+
gem.license = "MIT"
|
21
|
+
gem.summary = "Wraps objects callbacks to EventMachine next ticks, so allows transparent multiplexing of objects which aren't multiplexable by default."
|
22
|
+
gem.email = "martinkozak@martinkozak.net"
|
23
|
+
gem.authors = ["Martin Kozák"]
|
24
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
25
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
26
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
27
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
28
|
+
end
|
29
|
+
Jeweler::RubygemsDotOrgTasks.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/em-wrapper.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
|
+
|
4
|
+
require "hash-utils/object"
|
5
|
+
require "object-proxy"
|
6
|
+
require "eventmachine"
|
7
|
+
|
8
|
+
##
|
9
|
+
# Core EventMachine module.
|
10
|
+
# @see http://rubyeventmachine.com/
|
11
|
+
#
|
12
|
+
|
13
|
+
module EM
|
14
|
+
|
15
|
+
##
|
16
|
+
# Wraps objects callbacks to EventMachine next ticks,
|
17
|
+
# so multiplexes them.
|
18
|
+
#
|
19
|
+
|
20
|
+
module Wrapper
|
21
|
+
|
22
|
+
##
|
23
|
+
# Creates new wrapper.
|
24
|
+
#
|
25
|
+
# @param [Object, Class] cls wrapped object or class
|
26
|
+
# @return [Object, Class] another object or class of the same class linked to original object
|
27
|
+
#
|
28
|
+
|
29
|
+
def self.new(cls)
|
30
|
+
op = OP::catch(cls)
|
31
|
+
|
32
|
+
worker = Proc::new do |object|
|
33
|
+
object.method_call do |name, args, block|
|
34
|
+
object.wrapped.send(name, *args) do |result|
|
35
|
+
if not block.nil?
|
36
|
+
EM::next_tick do
|
37
|
+
result = [result] if not result.array?
|
38
|
+
block.call(*result)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
if cls.kind_of? Class
|
46
|
+
op.instance_created do |object|
|
47
|
+
worker.call(object)
|
48
|
+
end
|
49
|
+
else
|
50
|
+
worker.call(op)
|
51
|
+
end
|
52
|
+
|
53
|
+
return op
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
data/test
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
4
|
+
|
5
|
+
$:.push("./lib")
|
6
|
+
$:.unshift("./lib")
|
7
|
+
|
8
|
+
require "em-wrapper"
|
9
|
+
require "eventmachine"
|
10
|
+
|
11
|
+
class Foo
|
12
|
+
def foo
|
13
|
+
yield :foo
|
14
|
+
return :bar
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
wrapped = EM::Wrapper::new(Foo)::new
|
19
|
+
EM::run do
|
20
|
+
p wrapped.foo { |value| # will print :bar out
|
21
|
+
p value # will be run in next EM tick, will print :foo out
|
22
|
+
}
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: em-wrapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Martin Kozák
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: object-proxy
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.3.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.3.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: hash-utils
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.17.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.17.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: eventmachine
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.0.0
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.0.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: jeweler2
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.0.0
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 2.0.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: riot
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 0.12.3
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.12.3
|
110
|
+
description:
|
111
|
+
email: martinkozak@martinkozak.net
|
112
|
+
executables: []
|
113
|
+
extensions: []
|
114
|
+
extra_rdoc_files:
|
115
|
+
- LICENSE.txt
|
116
|
+
- README.md
|
117
|
+
files:
|
118
|
+
- .document
|
119
|
+
- Gemfile
|
120
|
+
- Gemfile.lock
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- VERSION
|
125
|
+
- lib/em-wrapper.rb
|
126
|
+
- test
|
127
|
+
homepage: http://github.com/martinkozak/em-wrapper
|
128
|
+
licenses:
|
129
|
+
- MIT
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
none: false
|
136
|
+
requirements:
|
137
|
+
- - ! '>='
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
segments:
|
141
|
+
- 0
|
142
|
+
hash: 3850679660524317222
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
none: false
|
145
|
+
requirements:
|
146
|
+
- - ! '>='
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 1.8.24
|
152
|
+
signing_key:
|
153
|
+
specification_version: 3
|
154
|
+
summary: Wraps objects callbacks to EventMachine next ticks, so allows transparent
|
155
|
+
multiplexing of objects which aren't multiplexable by default.
|
156
|
+
test_files: []
|