asir 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +8 -0
- data/asir.gemspec +0 -1
- data/lib/asir/additional_data.rb +1 -0
- data/lib/asir/code_more.rb +23 -8
- data/lib/asir/coder.rb +3 -0
- data/lib/asir/coder/database.rb +89 -0
- data/lib/asir/coder/identity.rb +0 -3
- data/lib/asir/coder/json.rb +2 -3
- data/lib/asir/coder/null.rb +0 -3
- data/lib/asir/coder/xml.rb +2 -0
- data/lib/asir/transport.rb +8 -5
- data/lib/asir/transport/database.rb +48 -0
- data/lib/asir/version.rb +1 -1
- data/spec/json_spec.rb +27 -13
- data/spec/message_spec.rb +29 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/xml_spec.rb +24 -24
- metadata +6 -4
data/ChangeLog
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
2012-11-30 Kurt A. Stephens <ks.github@kurtstephens.com>
|
2
|
+
|
3
|
+
* v1.0.8: New version.
|
4
|
+
* Database: Preliminary support for storing Message and Result objects
|
5
|
+
in a database: see gem asir_activerecord.
|
6
|
+
* Coder: Use Coder#prepare instead of Object#dup to handle statefulness.
|
7
|
+
* CodeMore: Use @receiver_name to disambiguate Modules vs. Instances.
|
8
|
+
|
1
9
|
2012-11-27 Kurt A. Stephens <ks.github@kurtstephens.com>
|
2
10
|
|
3
11
|
* v1.0.7: New version.
|
data/asir.gemspec
CHANGED
data/lib/asir/additional_data.rb
CHANGED
data/lib/asir/code_more.rb
CHANGED
@@ -7,11 +7,16 @@ module ASIR
|
|
7
7
|
include ObjectResolving # resolve_object()
|
8
8
|
include CodeBlock # encode_block!, decode_block!
|
9
9
|
|
10
|
+
attr_accessor :receiver_name
|
11
|
+
|
10
12
|
def encode_more!
|
11
13
|
obj = encode_block! # may self.dup
|
12
14
|
unless ::String === @receiver_class
|
13
15
|
obj ||= self.dup # dont dup twice.
|
14
|
-
|
16
|
+
if ::Module === @receiver
|
17
|
+
obj.receiver_name = true
|
18
|
+
obj.receiver = @receiver.name
|
19
|
+
end
|
15
20
|
obj.receiver_class = @receiver_class.name
|
16
21
|
if resp = obj.result and resp.message == self
|
17
22
|
resp.message = obj
|
@@ -23,8 +28,9 @@ module ASIR
|
|
23
28
|
def decode_more!
|
24
29
|
decode_block!
|
25
30
|
if ::String === @receiver_class
|
31
|
+
# pp [ :decode_more!, self ]
|
26
32
|
@receiver_class = resolve_object(@receiver_class)
|
27
|
-
@receiver = resolve_object(@receiver) if
|
33
|
+
@receiver = resolve_object(@receiver) if @receiver_name
|
28
34
|
unless @receiver_class === @receiver
|
29
35
|
raise Error, "receiver #{@receiver.class.name} is not a #{@receiver_class}"
|
30
36
|
end
|
@@ -32,19 +38,28 @@ module ASIR
|
|
32
38
|
self
|
33
39
|
end
|
34
40
|
|
35
|
-
#
|
36
|
-
#
|
37
|
-
|
41
|
+
# If receiver is a Module (i.e. class or module message),
|
42
|
+
# Returns [ name of the Module, :'.' ]
|
43
|
+
# Otherwise
|
44
|
+
# Returns [ name of the receiver's Class, :'#' ]
|
45
|
+
def message_kind
|
38
46
|
case
|
39
47
|
when ::String === @receiver_class
|
40
|
-
|
48
|
+
[ @receiver_class, :'.' ]
|
41
49
|
when ::Module === @receiver
|
42
|
-
|
50
|
+
[ @receiver.name, :'.' ]
|
43
51
|
else
|
44
|
-
|
52
|
+
[ @receiver_class.name, :'#' ]
|
45
53
|
end
|
46
54
|
end
|
47
55
|
|
56
|
+
# Returns "Module.selector" if receiver is Module.
|
57
|
+
# Returns "Class#selector" if receiver is an instance.
|
58
|
+
def description
|
59
|
+
x = message_kind
|
60
|
+
"#{x[0]}#{x[1]}#{@selector}"
|
61
|
+
end
|
62
|
+
|
48
63
|
# Mixin for Result.
|
49
64
|
module Result
|
50
65
|
def encode_more!
|
data/lib/asir/coder.rb
CHANGED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'asir/coder'
|
2
|
+
|
3
|
+
module ASIR
|
4
|
+
class Coder
|
5
|
+
# !SLIDE
|
6
|
+
# Database Coder
|
7
|
+
#
|
8
|
+
# Construct a database object from a Message or Result object.
|
9
|
+
#
|
10
|
+
# obj = model.new(:object => partially encoded object, :original_object => original object, :payload => Binary)
|
11
|
+
# obj.payload
|
12
|
+
#
|
13
|
+
# See Transport::Database:
|
14
|
+
#
|
15
|
+
# obj.save!
|
16
|
+
class Database < self
|
17
|
+
# The model for Message objects.
|
18
|
+
attr_accessor :message_model
|
19
|
+
# The model for Result objects.
|
20
|
+
attr_accessor :result_model
|
21
|
+
# The model for everything else.
|
22
|
+
attr_accessor :other_model
|
23
|
+
|
24
|
+
# The coder object => object_payload, must code to some binary String.
|
25
|
+
attr_accessor :payload_coder, :additional_data_coder
|
26
|
+
|
27
|
+
# Callback: attrs = call(self, obj, attrs : Hash)
|
28
|
+
attr_accessor :before_model_new
|
29
|
+
# Callback: model_obj = call(self, obj, model_obj)
|
30
|
+
attr_accessor :after_model_new
|
31
|
+
|
32
|
+
def _encode in_obj
|
33
|
+
obj = in_obj
|
34
|
+
case
|
35
|
+
when Message === in_obj && message_model
|
36
|
+
model = message_model
|
37
|
+
when Result === in_obj && result_model
|
38
|
+
model = result_model
|
39
|
+
else
|
40
|
+
model = other_model
|
41
|
+
end
|
42
|
+
if model
|
43
|
+
obj = in_obj.encode_more!
|
44
|
+
# Prepare attributes for Model.
|
45
|
+
attrs = { :original_object => in_obj }
|
46
|
+
|
47
|
+
# Encode AdditionalData.
|
48
|
+
if AdditionalData === obj and ad = obj._additional_data
|
49
|
+
c = additional_data_coder || payload_coder
|
50
|
+
attrs[:additional_data] = c.prepare.encode(ad)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Results need links back to its Message.
|
54
|
+
if Result === obj and message = in_obj.message
|
55
|
+
attrs[:message_object] = message
|
56
|
+
# Do not encode entire Message in ResultModel#payload.
|
57
|
+
obj.message = nil
|
58
|
+
if message_id = message[:database_id]
|
59
|
+
attrs[:message_id] = message_id
|
60
|
+
end
|
61
|
+
obj[:external_id] ||= message[:external_id]
|
62
|
+
# pp [ :Result_attrs, attrs ]
|
63
|
+
end
|
64
|
+
|
65
|
+
# Encode Object payload
|
66
|
+
payload = payload_coder.prepare.encode(obj)
|
67
|
+
attrs[:object] = obj
|
68
|
+
attrs[:payload] = payload
|
69
|
+
|
70
|
+
if @before_model_new
|
71
|
+
attr = @before_model_new.call(self, in_obj, attrs)
|
72
|
+
end
|
73
|
+
m = model.new(attrs)
|
74
|
+
if @after_model_new
|
75
|
+
m = @after_model_new.call(self, in_obj, m)
|
76
|
+
end
|
77
|
+
obj = m
|
78
|
+
end
|
79
|
+
obj
|
80
|
+
end
|
81
|
+
|
82
|
+
def _decode obj
|
83
|
+
payload_coder.prepare.decode(obj.payload)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
# !SLIDE END
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
data/lib/asir/coder/identity.rb
CHANGED
data/lib/asir/coder/json.rb
CHANGED
data/lib/asir/coder/null.rb
CHANGED
data/lib/asir/coder/xml.rb
CHANGED
data/lib/asir/transport.rb
CHANGED
@@ -28,7 +28,7 @@ module ASIR
|
|
28
28
|
message.create_identifier! if needs_message_identifier? message
|
29
29
|
@before_send_message.call(self, message) if @before_send_message
|
30
30
|
relative_message_delay! message
|
31
|
-
message_payload = encoder.
|
31
|
+
message_payload = encoder.prepare.encode(message)
|
32
32
|
opaque_result = _send_message(message, message_payload)
|
33
33
|
receive_result(message, opaque_result)
|
34
34
|
end
|
@@ -41,7 +41,7 @@ module ASIR
|
|
41
41
|
@message_count ||= 0; @message_count += 1
|
42
42
|
additional_data = { }
|
43
43
|
if req_and_state = _receive_message(stream, additional_data)
|
44
|
-
message = req_and_state[0] = encoder.
|
44
|
+
message = req_and_state[0] = encoder.prepare.decode(req_and_state.first)
|
45
45
|
message.additional_data!.update(additional_data) if message
|
46
46
|
if @after_receive_message
|
47
47
|
@after_receive_message.call(self, message)
|
@@ -59,11 +59,14 @@ module ASIR
|
|
59
59
|
if @one_way && message.block
|
60
60
|
message.block.call(result)
|
61
61
|
else
|
62
|
-
|
63
|
-
|
62
|
+
# avoid sending back entire Message.
|
63
|
+
result.message = nil unless @coder_needs_result_message
|
64
|
+
result_payload = decoder.prepare.encode(result)
|
64
65
|
_send_result(message, result, result_payload, stream, message_state)
|
65
66
|
end
|
66
67
|
end
|
68
|
+
attr_accessor :coder_needs_result_message
|
69
|
+
|
67
70
|
# !SLIDE END
|
68
71
|
|
69
72
|
# !SLIDE
|
@@ -74,7 +77,7 @@ module ASIR
|
|
74
77
|
# * Extract Result result or exception.
|
75
78
|
def receive_result message, opaque_result
|
76
79
|
result_payload = _receive_result(message, opaque_result)
|
77
|
-
result = decoder.
|
80
|
+
result = decoder.prepare.decode(result_payload)
|
78
81
|
if result && ! message.one_way
|
79
82
|
if exc = result.exception
|
80
83
|
invoker.invoke!(exc, self)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'asir'
|
2
|
+
|
3
|
+
module ASIR
|
4
|
+
class Transport
|
5
|
+
# Transport that stores to any model class that responds to:
|
6
|
+
#
|
7
|
+
# obj.save!
|
8
|
+
# obj.database_id
|
9
|
+
#
|
10
|
+
# See Coder::Database
|
11
|
+
#
|
12
|
+
class Database < self
|
13
|
+
attr_accessor :before_message_save, :after_message_save
|
14
|
+
attr_accessor :before_result_save, :after_result_save
|
15
|
+
|
16
|
+
def initialize *args
|
17
|
+
super
|
18
|
+
self.coder_needs_result_message = true
|
19
|
+
self.needs_message_identifier = true
|
20
|
+
end
|
21
|
+
|
22
|
+
def _send_message message, message_payload
|
23
|
+
if @before_message_save
|
24
|
+
@before_message_save.call(self, message, message_payload)
|
25
|
+
end
|
26
|
+
message_payload.save!
|
27
|
+
# message[:database_id] ||= message_payload.database_id
|
28
|
+
if @after_message_save
|
29
|
+
@after_message_save.call(self, message, message_payload)
|
30
|
+
end
|
31
|
+
nil # message_state
|
32
|
+
end
|
33
|
+
|
34
|
+
def _send_result message, result, result_payload, stream, message_state
|
35
|
+
return if one_way? or message.one_way?
|
36
|
+
if @before_result_save
|
37
|
+
@before_result_save.call(self, message, result, result_payload)
|
38
|
+
end
|
39
|
+
result_payload.save!
|
40
|
+
result[:database_id] = result_payload.database_id
|
41
|
+
if @after_result_save
|
42
|
+
@after_result_save.call(self, message, result, result_payload)
|
43
|
+
end
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/asir/version.rb
CHANGED
data/spec/json_spec.rb
CHANGED
@@ -19,9 +19,9 @@ describe "ASIR::Coder::JSON" do
|
|
19
19
|
str = "[#{str}]"
|
20
20
|
basic_objs << [ x, str ]
|
21
21
|
it "should handle #{x.inspect}" do
|
22
|
-
out = @enc.encode(x)
|
22
|
+
out = @enc.prepare.encode(x)
|
23
23
|
out.should == str
|
24
|
-
@dec.decode(out).should == x
|
24
|
+
@dec.prepare.decode(out).should == x
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -35,9 +35,9 @@ describe "ASIR::Coder::JSON" do
|
|
35
35
|
str = "[#{str}]"
|
36
36
|
basic_objs << [ x, str ]
|
37
37
|
it "should handle #{x.inspect}" do
|
38
|
-
out = @enc.encode(x)
|
38
|
+
out = @enc.prepare.encode(x)
|
39
39
|
out.should == str
|
40
|
-
y = @dec.decode(out)
|
40
|
+
y = @dec.prepare.decode(out)
|
41
41
|
y = y.to_sym if Symbol === x
|
42
42
|
y.should == x
|
43
43
|
end
|
@@ -51,18 +51,18 @@ describe "ASIR::Coder::JSON" do
|
|
51
51
|
str = "[#{str}]"
|
52
52
|
basic_objs << [ x, str ]
|
53
53
|
it "should handle #{x.inspect}" do
|
54
|
-
out = @enc.encode(x)
|
54
|
+
out = @enc.prepare.encode(x)
|
55
55
|
out.should == str
|
56
|
-
y = @dec.decode(out)
|
56
|
+
y = @dec.prepare.decode(out)
|
57
57
|
y.should == x
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should handle empty Array" do
|
62
62
|
x = [ ]
|
63
|
-
out = @enc.encode(x)
|
63
|
+
out = @enc.prepare.encode(x)
|
64
64
|
out.should == "[[]]"
|
65
|
-
@dec.decode(out).should == x
|
65
|
+
@dec.prepare.decode(out).should == x
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should handle Array" do
|
@@ -82,14 +82,14 @@ describe "ASIR::Coder::JSON" do
|
|
82
82
|
|
83
83
|
it "should handle Hash" do
|
84
84
|
x = Hash[ *basic_objs.flatten.reverse ]
|
85
|
-
out = @enc.encode(x)
|
85
|
+
out = @enc.prepare.encode(x)
|
86
86
|
out.should =~ %r{\A\[\{}
|
87
87
|
out.should =~ %r{\}\]\Z}
|
88
88
|
basic_objs.each do | v, str |
|
89
89
|
# out.should =~ %r{#{k.inspect}:}
|
90
90
|
out.should =~ %r{#{str}}
|
91
91
|
end
|
92
|
-
y = @dec.decode(out)
|
92
|
+
y = @dec.prepare.decode(out)
|
93
93
|
y.should == x.inject({}){|h, (k, v)| h[k] = Symbol === v ? v.to_s : v; h }
|
94
94
|
end
|
95
95
|
|
@@ -105,12 +105,26 @@ describe "ASIR::Coder::JSON" do
|
|
105
105
|
x.h = Hash[ *basic_objs.flatten.reverse ]
|
106
106
|
x.o = ASIR::Coder::Test::Object.new
|
107
107
|
x.o.a = 123
|
108
|
-
out = @enc.encode(x)
|
108
|
+
out = @enc.prepare.encode(x)
|
109
|
+
if out =~ %r{#<ASIR::Coder::Test::Object}
|
110
|
+
out.should =~ %r{\A\[\"#<ASIR::Coder::Test::Object:[^>]+>\"\]\Z}
|
111
|
+
else
|
112
|
+
out.should =~ %r{"a":\[null,true,false,1234,1.234,"symbol","String"\]}
|
113
|
+
out.should =~ %r{"h":\{}
|
114
|
+
out.should =~ %r{"\[1234\]":1234}
|
115
|
+
out.should =~ %r{"\[1.234\]":1.234}
|
116
|
+
out.should =~ %r{"\[null\]":null}
|
117
|
+
out.should =~ %r{"\[\\"String\\"\]":"String"}
|
118
|
+
out.should =~ %r{"\[\\"symbol\\"\]":"symbol"}
|
119
|
+
out.should =~ %r{"\[null\]":null}
|
120
|
+
out.should =~ %r{"\[true\]":true}
|
121
|
+
out.should =~ %r{"\[null\]":null}
|
122
|
+
end
|
123
|
+
|
109
124
|
# FIXME:
|
110
|
-
out.should =~ %r{\A\[\"#<ASIR::Coder::Test::Object:[^>]+>\"\]\Z}
|
111
125
|
#out.should =~ %r{<#{x.class.name.gsub('::', '.')} id=\"#{x.object_id}\" >}
|
112
126
|
#out.should =~ %r{</#{x.class.name.gsub('::', '.')}>}
|
113
|
-
y = @dec.decode(out)
|
127
|
+
y = @dec.prepare.decode(out)
|
114
128
|
(String === y).should == true
|
115
129
|
=begin
|
116
130
|
FIXME:
|
data/spec/message_spec.rb
CHANGED
@@ -64,5 +64,34 @@ describe "ASIR::Message" do
|
|
64
64
|
exc.exception_message.should == "#{cls.name} #{msg}"
|
65
65
|
exc.exception_backtrace.class.should == Array
|
66
66
|
end
|
67
|
+
|
68
|
+
it 'should return appropriate message_kind and #description.' do
|
69
|
+
self.object = ASIR::Coder.new
|
70
|
+
self.message = ASIR::Message.new(object, nil, nil, nil, nil)
|
71
|
+
message.selector = :instance_message!
|
72
|
+
|
73
|
+
x = message.description
|
74
|
+
x.should == "ASIR::Coder#instance_message!"
|
75
|
+
message.encode_more!
|
76
|
+
message.description.should == x
|
77
|
+
|
78
|
+
self.object = ASIR::Coder
|
79
|
+
self.message = ASIR::Message.new(object, nil, nil, nil, nil)
|
80
|
+
message.selector = :class_message!
|
81
|
+
|
82
|
+
x = message.description
|
83
|
+
x.should == "ASIR::Coder.class_message!"
|
84
|
+
message.encode_more!
|
85
|
+
message.description.should == x
|
86
|
+
|
87
|
+
self.object = ASIR
|
88
|
+
self.message = ASIR::Message.new(object, nil, nil, nil, nil)
|
89
|
+
message.selector = :module_message!
|
90
|
+
|
91
|
+
x = message.description
|
92
|
+
x.should == "ASIR.module_message!"
|
93
|
+
message.encode_more!
|
94
|
+
message.description.should == x
|
95
|
+
end
|
67
96
|
end
|
68
97
|
|
data/spec/spec_helper.rb
CHANGED
data/spec/xml_spec.rb
CHANGED
@@ -16,9 +16,9 @@ describe "ASIR::Coder::XML" do
|
|
16
16
|
].each do | x |
|
17
17
|
basic_objs << x
|
18
18
|
it "should handle #{x.inspect}" do
|
19
|
-
xml = @enc.encode(x)
|
19
|
+
xml = @enc.prepare.encode(x)
|
20
20
|
xml.should == "<#{x.class.name} />"
|
21
|
-
@dec.decode(xml).should == x
|
21
|
+
@dec.prepare.decode(xml).should == x
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -28,9 +28,9 @@ describe "ASIR::Coder::XML" do
|
|
28
28
|
].each do | x |
|
29
29
|
basic_objs << x
|
30
30
|
it "should handle #{x.inspect}" do
|
31
|
-
xml = @enc.encode(x)
|
31
|
+
xml = @enc.prepare.encode(x)
|
32
32
|
xml.should == "<#{x.class.name} v=\"#{x.to_s}\" />"
|
33
|
-
@dec.decode(xml).should == x
|
33
|
+
@dec.prepare.decode(xml).should == x
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -39,9 +39,9 @@ describe "ASIR::Coder::XML" do
|
|
39
39
|
].each do | x |
|
40
40
|
basic_objs << x
|
41
41
|
it "should handle #{x.inspect}" do
|
42
|
-
xml = @enc.encode(x)
|
42
|
+
xml = @enc.prepare.encode(x)
|
43
43
|
xml.should == "<#{x.class.name} >#{x.to_s}</#{x.class.name}>"
|
44
|
-
@dec.decode(xml).should == x
|
44
|
+
@dec.prepare.decode(xml).should == x
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -50,36 +50,36 @@ describe "ASIR::Coder::XML" do
|
|
50
50
|
].each do | x |
|
51
51
|
basic_objs << x
|
52
52
|
it "should handle #{x.inspect}" do
|
53
|
-
xml = @enc.encode(x)
|
53
|
+
xml = @enc.prepare.encode(x)
|
54
54
|
xml.should == "<#{x.class.name} id=\"1\" >#{x.to_s}</#{x.class.name}>"
|
55
|
-
@dec.decode(xml).should == x
|
55
|
+
@dec.prepare.decode(xml).should == x
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should handle empty Array" do
|
60
60
|
x = [ ]
|
61
|
-
xml = @enc.encode(x)
|
61
|
+
xml = @enc.prepare.encode(x)
|
62
62
|
xml.should == "<#{x.class.name} id=\"1\" ></#{x.class.name}>"
|
63
|
-
@dec.decode(xml).should == x
|
63
|
+
@dec.prepare.decode(xml).should == x
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should handle Array" do
|
67
67
|
x = [ *basic_objs ]
|
68
|
-
xml = @enc.encode(x)
|
68
|
+
xml = @enc.prepare.encode(x)
|
69
69
|
xml.should =~ %r{\A<#{x.class.name} id=\"1\" ><NilClass /><TrueClass /><FalseClass /><Fixnum v="1234" /><Float v="1.234" /><Symbol >symbol</Symbol><String id=\"[^"]+\" >String</String></#{x.class.name}>\Z} # " emacs
|
70
|
-
@dec.decode(xml).should == x
|
70
|
+
@dec.prepare.decode(xml).should == x
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should handle empty Hash" do
|
74
74
|
x = { }
|
75
|
-
xml = @enc.encode(x)
|
75
|
+
xml = @enc.prepare.encode(x)
|
76
76
|
xml.should == "<#{x.class.name} id=\"1\" ></#{x.class.name}>"
|
77
|
-
@dec.decode(xml).should == x
|
77
|
+
@dec.prepare.decode(xml).should == x
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should handle Hash" do
|
81
81
|
x = Hash[ *basic_objs.map{|e| e.inspect}.zip(basic_objs).flatten ]
|
82
|
-
xml = @enc.encode(x)
|
82
|
+
xml = @enc.prepare.encode(x)
|
83
83
|
xml.should =~ %r{\A<#{x.class.name} id=\"1\" >}
|
84
84
|
xml.should =~ %r{</#{x.class.name}>\Z}
|
85
85
|
basic_objs.each do | v |
|
@@ -88,7 +88,7 @@ describe "ASIR::Coder::XML" do
|
|
88
88
|
xml.should =~ Regexp.new(vx)
|
89
89
|
xml.should =~ %r{ >#{v.inspect}</String>}
|
90
90
|
end
|
91
|
-
@dec.decode(xml).should == x
|
91
|
+
@dec.prepare.decode(xml).should == x
|
92
92
|
end
|
93
93
|
|
94
94
|
class ASIR::Coder::XML::Test
|
@@ -101,10 +101,10 @@ describe "ASIR::Coder::XML" do
|
|
101
101
|
x.h = Hash[ *basic_objs.map{|e| e.inspect}.zip(basic_objs).flatten ]
|
102
102
|
x.o = ASIR::Coder::XML::Test.new
|
103
103
|
x.o.a = 123
|
104
|
-
xml = @enc.encode(x)
|
104
|
+
xml = @enc.prepare.encode(x)
|
105
105
|
xml.should =~ %r{<#{x.class.name.gsub('::', '.')} id=\"1\" >}
|
106
106
|
xml.should =~ %r{</#{x.class.name.gsub('::', '.')}>}
|
107
|
-
y = @dec.decode(xml)
|
107
|
+
y = @dec.prepare.decode(xml)
|
108
108
|
y.a.should == x.a
|
109
109
|
y.h.should == x.h
|
110
110
|
y.o.class.should == ASIR::Coder::XML::Test
|
@@ -117,8 +117,8 @@ describe "ASIR::Coder::XML" do
|
|
117
117
|
x = Hash[ *basic_objs.map{|e| e.inspect}.zip(basic_objs).flatten ]
|
118
118
|
y = [ 1, 2 ]
|
119
119
|
x = [ x, x, y, y ]
|
120
|
-
xml = @enc.encode(x)
|
121
|
-
y = @dec.decode(xml)
|
120
|
+
xml = @enc.prepare.encode(x)
|
121
|
+
y = @dec.prepare.decode(xml)
|
122
122
|
y[0].object_id.should == y[1].object_id
|
123
123
|
y[2].object_id.should == y[3].object_id
|
124
124
|
end
|
@@ -126,8 +126,8 @@ describe "ASIR::Coder::XML" do
|
|
126
126
|
it "should handle self-referencing Array." do
|
127
127
|
x = [ 1 ]
|
128
128
|
x << x
|
129
|
-
xml = @enc.encode(x)
|
130
|
-
y = @dec.decode(xml)
|
129
|
+
xml = @enc.prepare.encode(x)
|
130
|
+
y = @dec.prepare.decode(xml)
|
131
131
|
y[0].should == x[0]
|
132
132
|
y[1].object_id.should == y.object_id
|
133
133
|
end
|
@@ -135,8 +135,8 @@ describe "ASIR::Coder::XML" do
|
|
135
135
|
it "should handle self-referencing Hash." do
|
136
136
|
x = { :a => 1 }
|
137
137
|
x[:self] = x
|
138
|
-
xml = @enc.encode(x)
|
139
|
-
y = @dec.decode(xml)
|
138
|
+
xml = @enc.prepare.encode(x)
|
139
|
+
y = @dec.prepare.decode(xml)
|
140
140
|
y[:a].should == x[:a]
|
141
141
|
y[:self].object_id.should == y.object_id
|
142
142
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asir
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: uuid
|
@@ -286,6 +286,7 @@ files:
|
|
286
286
|
- lib/asir/coder.rb
|
287
287
|
- lib/asir/coder/base64.rb
|
288
288
|
- lib/asir/coder/chain.rb
|
289
|
+
- lib/asir/coder/database.rb
|
289
290
|
- lib/asir/coder/identity.rb
|
290
291
|
- lib/asir/coder/json.rb
|
291
292
|
- lib/asir/coder/marshal.rb
|
@@ -319,6 +320,7 @@ files:
|
|
319
320
|
- lib/asir/transport/composite.rb
|
320
321
|
- lib/asir/transport/conduit.rb
|
321
322
|
- lib/asir/transport/connection_oriented.rb
|
323
|
+
- lib/asir/transport/database.rb
|
322
324
|
- lib/asir/transport/delay.rb
|
323
325
|
- lib/asir/transport/delegation.rb
|
324
326
|
- lib/asir/transport/demux.rb
|
@@ -367,7 +369,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
367
369
|
version: '0'
|
368
370
|
segments:
|
369
371
|
- 0
|
370
|
-
hash:
|
372
|
+
hash: 885978386070956346
|
371
373
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
372
374
|
none: false
|
373
375
|
requirements:
|
@@ -376,7 +378,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
376
378
|
version: '0'
|
377
379
|
segments:
|
378
380
|
- 0
|
379
|
-
hash:
|
381
|
+
hash: 885978386070956346
|
380
382
|
requirements: []
|
381
383
|
rubyforge_project:
|
382
384
|
rubygems_version: 1.8.24
|