bertrpc 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,3 @@
1
+ = 0.4.0 / 2009-10-08
2
+ * Major changes
3
+ * Convert to use BERT gem.
data/Rakefile CHANGED
@@ -9,6 +9,7 @@ begin
9
9
  gem.email = "tom@mojombo.com"
10
10
  gem.homepage = "http://github.com/mojombo/bertrpc"
11
11
  gem.authors = ["Tom Preston-Werner"]
12
+ gem.add_dependency('bert', '>= 0.1.0')
12
13
  gem.add_dependency('erlectricity', '>= 1.0.1')
13
14
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
15
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.4.0
data/bertrpc.gemspec CHANGED
@@ -1,12 +1,15 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
1
4
  # -*- encoding: utf-8 -*-
2
5
 
3
6
  Gem::Specification.new do |s|
4
7
  s.name = %q{bertrpc}
5
- s.version = "0.3.4"
8
+ s.version = "0.4.0"
6
9
 
7
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
11
  s.authors = ["Tom Preston-Werner"]
9
- s.date = %q{2009-09-25}
12
+ s.date = %q{2009-10-08}
10
13
  s.email = %q{tom@mojombo.com}
11
14
  s.extra_rdoc_files = [
12
15
  "LICENSE",
@@ -15,6 +18,7 @@ Gem::Specification.new do |s|
15
18
  s.files = [
16
19
  ".document",
17
20
  ".gitignore",
21
+ "History.txt",
18
22
  "LICENSE",
19
23
  "README.md",
20
24
  "Rakefile",
@@ -55,11 +59,14 @@ Gem::Specification.new do |s|
55
59
  s.specification_version = 3
56
60
 
57
61
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
62
+ s.add_runtime_dependency(%q<bert>, [">= 0.1.0"])
58
63
  s.add_runtime_dependency(%q<erlectricity>, [">= 1.0.1"])
59
64
  else
65
+ s.add_dependency(%q<bert>, [">= 0.1.0"])
60
66
  s.add_dependency(%q<erlectricity>, [">= 1.0.1"])
61
67
  end
62
68
  else
69
+ s.add_dependency(%q<bert>, [">= 0.1.0"])
63
70
  s.add_dependency(%q<erlectricity>, [">= 1.0.1"])
64
71
  end
65
72
  end
@@ -11,7 +11,7 @@ module BERTRPC
11
11
  end
12
12
 
13
13
  def execute
14
- bert_request = encode_ruby_request([@req.kind, @mod, @fun, @args])
14
+ bert_request = encode_ruby_request(t[@req.kind, @mod, @fun, @args])
15
15
  bert_response = transaction(bert_request)
16
16
  decode_bert_response(bert_response)
17
17
  end
@@ -1,15 +1,14 @@
1
1
  module BERTRPC
2
2
  module Encodes
3
3
  def encode_ruby_request(ruby_request)
4
- ruby_payload = convert(ruby_request)
5
- Erlectricity::Encoder.encode(ruby_payload)
4
+ BERT.encode(ruby_request)
6
5
  end
7
6
 
8
7
  def decode_bert_response(bert_response)
9
- ruby_response = Erlectricity::Decoder.decode(bert_response)
8
+ ruby_response = BERT.decode(bert_response)
10
9
  case ruby_response[0]
11
10
  when :reply
12
- deconvert(ruby_response[1])
11
+ ruby_response[1]
13
12
  when :noreply
14
13
  nil
15
14
  when :error
@@ -35,31 +34,5 @@ module BERTRPC
35
34
  raise
36
35
  end
37
36
  end
38
-
39
- def convert(item)
40
- if item.instance_of?(Hash)
41
- a = [:dict]
42
- item.each_pair { |k, v| a << [convert(k), convert(v)] }
43
- a
44
- elsif item.instance_of?(Array)
45
- item.map { |x| convert(x) }
46
- else
47
- item
48
- end
49
- end
50
-
51
- def deconvert(item)
52
- if item.instance_of?(Array)
53
- if item.first == :dict
54
- item[1..-1].inject({}) do |acc, x|
55
- acc[deconvert(x[0])] = deconvert(x[1]); acc
56
- end
57
- else
58
- item.map { |x| deconvert(x) }
59
- end
60
- else
61
- item
62
- end
63
- end
64
37
  end
65
38
  end
data/lib/bertrpc.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'erlectricity'
1
+ require 'bert'
2
2
  require 'socket'
3
3
 
4
4
  require 'bertrpc/service'
data/test/action_test.rb CHANGED
@@ -20,24 +20,24 @@ class ActionTest < Test::Unit::TestCase
20
20
  end
21
21
 
22
22
  should "call with single-arity" do
23
- req = @enc.encode_ruby_request([:call, :mymod, :myfun, [1]])
24
- res = @enc.encode_ruby_request([:reply, 2])
23
+ req = @enc.encode_ruby_request(t[:call, :mymod, :myfun, [1]])
24
+ res = @enc.encode_ruby_request(t[:reply, 2])
25
25
  call = BERTRPC::Action.new(@svc, @req, :mymod, :myfun, [1])
26
26
  call.expects(:transaction).with(req).returns(res)
27
27
  assert_equal 2, call.execute
28
28
  end
29
29
 
30
30
  should "call with single-arity array" do
31
- req = @enc.encode_ruby_request([:call, :mymod, :myfun, [[1, 2, 3]]])
32
- res = @enc.encode_ruby_request([:reply, [4, 5, 6]])
31
+ req = @enc.encode_ruby_request(t[:call, :mymod, :myfun, [[1, 2, 3]]])
32
+ res = @enc.encode_ruby_request(t[:reply, [4, 5, 6]])
33
33
  call = BERTRPC::Action.new(@svc, @req, :mymod, :myfun, [[1, 2, 3]])
34
34
  call.expects(:transaction).with(req).returns(res)
35
35
  assert_equal [4, 5, 6], call.execute
36
36
  end
37
37
 
38
38
  should "call with multi-arity" do
39
- req = @enc.encode_ruby_request([:call, :mymod, :myfun, [1, 2, 3]])
40
- res = @enc.encode_ruby_request([:reply, [4, 5, 6]])
39
+ req = @enc.encode_ruby_request(t[:call, :mymod, :myfun, [1, 2, 3]])
40
+ res = @enc.encode_ruby_request(t[:reply, [4, 5, 6]])
41
41
  call = BERTRPC::Action.new(@svc, @req, :mymod, :myfun, [1, 2, 3])
42
42
  call.expects(:transaction).with(req).returns(res)
43
43
  assert_equal [4, 5, 6], call.execute
data/test/encodes_test.rb CHANGED
@@ -6,66 +6,35 @@ class EncodesTest < Test::Unit::TestCase
6
6
  @enc = Enc.new
7
7
  end
8
8
 
9
- context "converter" do
10
- should "convert top level hashes to BERT-RPC dict form" do
11
- arr = @enc.convert({:foo => 1, :bar => 2})
12
- a = [:dict, [:foo, 1], [:bar, 2]] == arr
13
- b = [:dict, [:bar, 2], [:foo, 1]] == arr
14
- assert(a || b)
15
- end
16
-
17
- should "convert nested hashes in the same way" do
18
- assert_equal([1, 2, [:dict, [:foo, 1]]], @enc.convert([1, 2, {:foo => 1}]))
19
- end
20
-
21
- should "keep everything else the same" do
22
- assert_equal [1, 2, "foo", :bar, 3.14], @enc.convert([1, 2, "foo", :bar, 3.14])
23
- end
24
- end
25
-
26
- context "deconverter" do
27
- should "convert top level BERT-RPC dict forms to hashes" do
28
- assert_equal({:foo => 1, :bar => 2}, @enc.deconvert([:dict, [:foo, 1], [:bar, 2]]))
29
- end
30
-
31
- should "convert nested dicts in the same way" do
32
- assert_equal([1, 2, {:foo => 1}], @enc.deconvert([1, 2, [:dict, [:foo, 1]]]))
33
- end
34
-
35
- should "keep everything else the same" do
36
- assert_equal [1, 2, "foo", :bar, 3.14], @enc.deconvert([1, 2, "foo", :bar, 3.14])
37
- end
38
- end
39
-
40
9
  context "ruby request encoder" do
41
10
  should "return BERT-RPC encoded request" do
42
- bert = "\203h\004d\000\004calld\000\005mymodd\000\005myfunh\003a\001a\002a\003"
43
- assert_equal bert, @enc.encode_ruby_request([:call, :mymod, :myfun, [1, 2, 3]])
11
+ bert = "\203h\004d\000\004calld\000\005mymodd\000\005myfunl\000\000\000\003a\001a\002a\003j"
12
+ assert_equal bert, @enc.encode_ruby_request(t[:call, :mymod, :myfun, [1, 2, 3]])
44
13
  end
45
14
  end
46
15
 
47
16
  context "bert response decoder" do
48
17
  should "return response when reply" do
49
- req = @enc.encode_ruby_request([:reply, [1, 2, 3]])
18
+ req = @enc.encode_ruby_request(t[:reply, [1, 2, 3]])
50
19
  res = @enc.decode_bert_response(req)
51
20
  assert_equal [1, 2, 3], res
52
21
  end
53
22
 
54
23
  should "return nil when noreply" do
55
- req = @enc.encode_ruby_request([:noreply])
24
+ req = @enc.encode_ruby_request(t[:noreply])
56
25
  res = @enc.decode_bert_response(req)
57
26
  assert_equal nil, res
58
27
  end
59
28
 
60
29
  should "raise a ProtocolError error when protocol level error is returned" do
61
- req = @enc.encode_ruby_request([:error, [:protocol, 1, "class", "invalid", []]])
30
+ req = @enc.encode_ruby_request(t[:error, [:protocol, 1, "class", "invalid", []]])
62
31
  assert_raises(BERTRPC::ProtocolError) do
63
32
  @enc.decode_bert_response(req)
64
33
  end
65
34
  end
66
35
 
67
36
  should "raise a ServerError error when server level error is returned" do
68
- req = @enc.encode_ruby_request([:error, [:server, 1, "class", "invalid", []]])
37
+ req = @enc.encode_ruby_request(t[:error, [:server, 1, "class", "invalid", []]])
69
38
  assert_raises(BERTRPC::ServerError) do
70
39
  @enc.decode_bert_response(req)
71
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bertrpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Preston-Werner
@@ -9,9 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-25 00:00:00 -07:00
12
+ date: 2009-10-08 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bert
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.1.0
24
+ version:
15
25
  - !ruby/object:Gem::Dependency
16
26
  name: erlectricity
17
27
  type: :runtime
@@ -34,6 +44,7 @@ extra_rdoc_files:
34
44
  files:
35
45
  - .document
36
46
  - .gitignore
47
+ - History.txt
37
48
  - LICENSE
38
49
  - README.md
39
50
  - Rakefile