fraggle-synchrony-spanx 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +2 -0
- data/.gitignore +5 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +34 -0
- data/Rakefile +13 -0
- data/fraggle-synchrony.gemspec +28 -0
- data/lib/fraggle-synchrony.rb +10 -0
- data/lib/fraggle-synchrony/fraggle.rb +19 -0
- data/lib/fraggle-synchrony/fraggle/client.rb +28 -0
- data/lib/fraggle-synchrony/version.rb +5 -0
- data/spec/fraggle-synchrony/fraggle/client_spec.rb +104 -0
- data/spec/spec_helper.rb +81 -0
- metadata +126 -0
data/.autotest
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (C) 2011 by Digital Science
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
20
|
+
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
### Fraggle-synchrony
|
2
|
+
|
3
|
+
This is a Fiber-aware wrapper for the Fraggle EM library, which provides
|
4
|
+
an evented Ruby interface to [Doozer](https://github.com/ha/doozerd).
|
5
|
+
|
6
|
+
**NOTE:** This only runs on Ruby 1.9.2 due to the underlying use of Fibers.
|
7
|
+
|
8
|
+
Fraggle code can often become a bit of a spaghetti mess due to the
|
9
|
+
reliance on callbacks - wrapping with Synchrony allows you to replace:
|
10
|
+
|
11
|
+
Fraggle.connect do |client|
|
12
|
+
client.rev do |rev|
|
13
|
+
client.get rev, "/path/to/thing" do |value|
|
14
|
+
# do stuff with value
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
with
|
20
|
+
|
21
|
+
client = Fraggle.connect
|
22
|
+
rev = client.rev
|
23
|
+
value = client.get rev, "/path/to/thing"
|
24
|
+
# do stuff with value
|
25
|
+
|
26
|
+
The full list of supported commands is: rev, set, get, del, stat
|
27
|
+
|
28
|
+
wait is not supported - just use the standard aynch callback mechanism
|
29
|
+
provided by Fraggle (a pseudo-blocking wait command makes no sense).
|
30
|
+
|
31
|
+
All using Fibers ensuring the code is still fully asynchronous. Pretty
|
32
|
+
awesome huh? (bear in mind 99% of the awesomeness is clearly due to Ilya
|
33
|
+
Grigorik and his wonderful [em-synchrony](https://github.com/igrigorik/em-synchrony), not me :)
|
34
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
|
5
|
+
Bundler.require(:default, :test)
|
6
|
+
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new do |t|
|
10
|
+
t.pattern = "**/*_spec.rb"
|
11
|
+
t.rspec_opts = ["--format", "documentation", "--colour"]
|
12
|
+
end
|
13
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "fraggle-synchrony/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "fraggle-synchrony-spanx"
|
7
|
+
s.version = Fraggle::Synchrony::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Steven Mohapi-Banks", "John Griffin"]
|
10
|
+
s.email = ["steven.mohapibanks@gmail.com", "johnog@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{An em-synchrony wrapper for fraggle}
|
13
|
+
s.description = s.summary
|
14
|
+
|
15
|
+
s.rubyforge_project = "fraggle-synchrony"
|
16
|
+
|
17
|
+
s.add_dependency "fraggle"
|
18
|
+
s.add_dependency "em-synchrony"
|
19
|
+
|
20
|
+
s.add_development_dependency "rake", ">= 0.8.7"
|
21
|
+
s.add_development_dependency "rspec", ">= 2.0"
|
22
|
+
|
23
|
+
s.files = `git ls-files`.split("\n")
|
24
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
25
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
26
|
+
s.require_paths = ["lib"]
|
27
|
+
s.add_dependency "beefcake-spanx"
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Fraggle
|
2
|
+
|
3
|
+
class << self
|
4
|
+
alias :aconnect :connect
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.connect(uri = nil)
|
8
|
+
f = Fiber.current
|
9
|
+
|
10
|
+
cb = proc { |client, err|
|
11
|
+
f.resume client || err
|
12
|
+
}
|
13
|
+
self.aconnect(uri, &cb)
|
14
|
+
|
15
|
+
response = Fiber.yield
|
16
|
+
raise response if response.is_a?(StandardError)
|
17
|
+
response
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Fraggle
|
2
|
+
class Client
|
3
|
+
|
4
|
+
%w{rev set get del stat getdir walk}.each do |cmd|
|
5
|
+
class_eval <<-CODE
|
6
|
+
alias :a#{cmd} :#{cmd}
|
7
|
+
|
8
|
+
def #{cmd}(*args, &blk)
|
9
|
+
f = Fiber.current
|
10
|
+
blk = proc{ |v| v } if !block_given?
|
11
|
+
cb = proc { |e, err|
|
12
|
+
if err
|
13
|
+
f.resume err
|
14
|
+
else
|
15
|
+
f.resume blk.call(e)
|
16
|
+
end
|
17
|
+
}
|
18
|
+
a#{cmd}(*args, &cb)
|
19
|
+
|
20
|
+
response = Fiber.yield
|
21
|
+
raise response if response.is_a?(StandardError)
|
22
|
+
response
|
23
|
+
end
|
24
|
+
CODE
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fraggle::Client do
|
4
|
+
|
5
|
+
it "should retrieve rev" do
|
6
|
+
EM.synchrony {
|
7
|
+
initialize_server(DoozerConnection)
|
8
|
+
client = Fraggle.connect("doozer:?ca=127.0.0.1:9876")
|
9
|
+
response = client.rev
|
10
|
+
response.should == 2
|
11
|
+
EM.stop
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should trap an error from rev" do
|
16
|
+
EM.synchrony {
|
17
|
+
initialize_server(BadDoozerConnection)
|
18
|
+
client = Fraggle.connect("doozer:?ca=127.0.0.1:9876")
|
19
|
+
expect {
|
20
|
+
client.rev
|
21
|
+
}.to raise_error(Fraggle::Connection::ResponseError)
|
22
|
+
EM.stop
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should set a value" do
|
27
|
+
EM.synchrony {
|
28
|
+
initialize_server(DoozerConnection)
|
29
|
+
client = Fraggle.connect("doozer:?ca=127.0.0.1:9876")
|
30
|
+
response = client.set(3, "/path", "value")
|
31
|
+
response.rev.should == 4
|
32
|
+
EM.stop
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should trap an error from set" do
|
37
|
+
EM.synchrony {
|
38
|
+
initialize_server(BadDoozerConnection)
|
39
|
+
client = Fraggle.connect("doozer:?ca=127.0.0.1:9876")
|
40
|
+
expect {
|
41
|
+
client.set(3, "/path", "value")
|
42
|
+
}.to raise_error(Fraggle::Connection::ResponseError)
|
43
|
+
EM.stop
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should get a value" do
|
48
|
+
EM.synchrony {
|
49
|
+
initialize_server(DoozerConnection)
|
50
|
+
client = Fraggle.connect("doozer:?ca=127.0.0.1:9876")
|
51
|
+
response = client.get(5, "/path")
|
52
|
+
response.rev.should == 6
|
53
|
+
response.value.should == "VALUE"
|
54
|
+
EM.stop
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should trap an error from get" do
|
59
|
+
EM.synchrony {
|
60
|
+
initialize_server(BadDoozerConnection)
|
61
|
+
client = Fraggle.connect("doozer:?ca=127.0.0.1:9876")
|
62
|
+
expect {
|
63
|
+
client.get(2, "/path")
|
64
|
+
}.to raise_error(Fraggle::Connection::ResponseError)
|
65
|
+
EM.stop
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should del a value" do
|
70
|
+
EM.synchrony {
|
71
|
+
initialize_server(DoozerConnection)
|
72
|
+
client = Fraggle.connect("doozer:?ca=127.0.0.1:9876")
|
73
|
+
response = client.del(7, "/path")
|
74
|
+
response.rev.should == 8
|
75
|
+
EM.stop
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should trap an error from del" do
|
80
|
+
EM.synchrony {
|
81
|
+
initialize_server(BadDoozerConnection)
|
82
|
+
client = Fraggle.connect("doozer:?ca=127.0.0.1:9876")
|
83
|
+
expect {
|
84
|
+
client.del(7, "/path")
|
85
|
+
}.to raise_error(Fraggle::Connection::ResponseError)
|
86
|
+
EM.stop
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should returns stat" do
|
91
|
+
EM.synchrony {
|
92
|
+
initialize_server(DoozerConnection)
|
93
|
+
client = Fraggle.connect("doozer:?ca=127.0.0.1:9876")
|
94
|
+
response = client.stat(9, "/path")
|
95
|
+
response.rev.should == 10
|
96
|
+
response.value.should == "STAT"
|
97
|
+
EM.stop
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
101
|
+
def initialize_server(connection_class)
|
102
|
+
EM::start_server "127.0.0.1", 9876, connection_class
|
103
|
+
end
|
104
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
|
3
|
+
require 'fraggle-synchrony'
|
4
|
+
require 'eventmachine'
|
5
|
+
|
6
|
+
class DoozerConnection < EM::Connection
|
7
|
+
def receive_data(data)
|
8
|
+
request = Fraggle::Request.decode(data)
|
9
|
+
response = Fraggle::Response.new
|
10
|
+
response.tag = request.tag
|
11
|
+
__send__ :"__#{verb_to_s(request.verb)}__", request, response
|
12
|
+
end
|
13
|
+
def __ACCESS__(request, response)
|
14
|
+
send_response(response)
|
15
|
+
end
|
16
|
+
def __REV__(request, response)
|
17
|
+
response.rev = 2
|
18
|
+
send_response(response)
|
19
|
+
end
|
20
|
+
def __SET__(request, response)
|
21
|
+
response.rev = 4
|
22
|
+
send_response(response)
|
23
|
+
end
|
24
|
+
def __GET__(request, response)
|
25
|
+
response.rev = 6
|
26
|
+
response.value = "VALUE"
|
27
|
+
send_response(response)
|
28
|
+
end
|
29
|
+
def __DEL__(request, response)
|
30
|
+
response.rev = 8
|
31
|
+
send_response(response)
|
32
|
+
end
|
33
|
+
def __STAT__(request, response)
|
34
|
+
response.rev = 10
|
35
|
+
response.value = "STAT"
|
36
|
+
send_response(response)
|
37
|
+
end
|
38
|
+
def send_response(response)
|
39
|
+
data = response.encode
|
40
|
+
head = [data.length].pack("N")
|
41
|
+
send_data("#{head}#{data}")
|
42
|
+
end
|
43
|
+
def verb_to_s(verb)
|
44
|
+
{
|
45
|
+
1 => "GET",
|
46
|
+
2 => "SET",
|
47
|
+
3 => "DEL",
|
48
|
+
5 => "REV",
|
49
|
+
6 => "WAIT",
|
50
|
+
7 => "NOP",
|
51
|
+
9 => "WALK",
|
52
|
+
14 => "GETDIR",
|
53
|
+
16 => "STAT",
|
54
|
+
99 => "ACCESS"
|
55
|
+
}[verb]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class BadDoozerConnection < DoozerConnection
|
60
|
+
def __REV__(request, response)
|
61
|
+
response.rev = 2
|
62
|
+
response.err_code = Fraggle::Response::Err::OTHER
|
63
|
+
send_response(response)
|
64
|
+
end
|
65
|
+
def __SET__(request, response)
|
66
|
+
response.rev = 4
|
67
|
+
response.err_code = Fraggle::Response::Err::OTHER
|
68
|
+
send_response(response)
|
69
|
+
end
|
70
|
+
def __GET__(request, response)
|
71
|
+
response.rev = 6
|
72
|
+
response.err_code = Fraggle::Response::Err::OTHER
|
73
|
+
send_response(response)
|
74
|
+
end
|
75
|
+
def __DEL__(request, response)
|
76
|
+
response.rev = 8
|
77
|
+
response.err_code = Fraggle::Response::Err::OTHER
|
78
|
+
send_response(response)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fraggle-synchrony-spanx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Steven Mohapi-Banks
|
9
|
+
- John Griffin
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2011-08-03 00:00:00.000000000 +01:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: fraggle
|
18
|
+
requirement: &70362654423280 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *70362654423280
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: em-synchrony
|
29
|
+
requirement: &70362654422580 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *70362654422580
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rake
|
40
|
+
requirement: &70362654421040 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.8.7
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *70362654421040
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rspec
|
51
|
+
requirement: &70362654419000 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '2.0'
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *70362654419000
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: beefcake-spanx
|
62
|
+
requirement: &70362654409340 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: *70362654409340
|
71
|
+
description: An em-synchrony wrapper for fraggle
|
72
|
+
email:
|
73
|
+
- steven.mohapibanks@gmail.com
|
74
|
+
- johnog@gmail.com
|
75
|
+
executables: []
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- .autotest
|
80
|
+
- .gitignore
|
81
|
+
- .rspec
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- fraggle-synchrony.gemspec
|
87
|
+
- lib/fraggle-synchrony.rb
|
88
|
+
- lib/fraggle-synchrony/fraggle.rb
|
89
|
+
- lib/fraggle-synchrony/fraggle/client.rb
|
90
|
+
- lib/fraggle-synchrony/version.rb
|
91
|
+
- spec/fraggle-synchrony/fraggle/client_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
has_rdoc: true
|
94
|
+
homepage: ''
|
95
|
+
licenses: []
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
hash: -4298698590582923812
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
hash: -4298698590582923812
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project: fraggle-synchrony
|
120
|
+
rubygems_version: 1.6.2
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: An em-synchrony wrapper for fraggle
|
124
|
+
test_files:
|
125
|
+
- spec/fraggle-synchrony/fraggle/client_spec.rb
|
126
|
+
- spec/spec_helper.rb
|