asir 1.1.4 → 1.1.5
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/ChangeLog +5 -0
- data/lib/asir/coder/yaml.rb +29 -1
- data/lib/asir/version.rb +1 -1
- data/spec/debug_helper.rb +1 -1
- data/spec/yaml_spec.rb +107 -0
- metadata +6 -4
data/ChangeLog
CHANGED
data/lib/asir/coder/yaml.rb
CHANGED
@@ -11,7 +11,7 @@ module ASIR
|
|
11
11
|
when Message, Result
|
12
12
|
obj = obj.encode_more!
|
13
13
|
end
|
14
|
-
|
14
|
+
yaml_dump(obj)
|
15
15
|
end
|
16
16
|
|
17
17
|
def _decode obj
|
@@ -22,7 +22,35 @@ module ASIR
|
|
22
22
|
obj
|
23
23
|
end
|
24
24
|
end
|
25
|
+
|
26
|
+
attr_accessor :yaml_options
|
27
|
+
case RUBY_VERSION
|
28
|
+
when /^1\.8/
|
29
|
+
def yaml_dump obj
|
30
|
+
::YAML::dump obj
|
31
|
+
end
|
32
|
+
else
|
33
|
+
def yaml_dump obj
|
34
|
+
::YAML::dump(obj, nil, yaml_options || EMPTY_HASH)
|
35
|
+
end
|
36
|
+
end
|
25
37
|
end # class
|
26
38
|
end # class
|
27
39
|
end # module
|
28
40
|
|
41
|
+
if defined? ::Psych
|
42
|
+
class Psych::Visitors::YAMLTree
|
43
|
+
alias :binary_without_option? :binary?
|
44
|
+
def binary? string
|
45
|
+
return false if @options[:never_binary]
|
46
|
+
result =
|
47
|
+
string.index("\x00") ||
|
48
|
+
string.count("\x00-\x7F", "^ -~\t\r\n").fdiv(string.length) > 0.3
|
49
|
+
unless @options[:ASCII_8BIT_ok]
|
50
|
+
result ||= string.encoding == Encoding::ASCII_8BIT
|
51
|
+
end
|
52
|
+
result
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
data/lib/asir/version.rb
CHANGED
data/spec/debug_helper.rb
CHANGED
data/spec/yaml_spec.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
require 'asir/coder/yaml'
|
3
|
+
|
4
|
+
describe "ASIR::Coder::Yaml" do
|
5
|
+
before(:each) do
|
6
|
+
@enc = ASIR::Coder::Yaml.new
|
7
|
+
@dec = @enc.dup
|
8
|
+
end
|
9
|
+
|
10
|
+
basic_objs = [ ]
|
11
|
+
|
12
|
+
[
|
13
|
+
[ nil, '' ],
|
14
|
+
true,
|
15
|
+
false,
|
16
|
+
123,
|
17
|
+
123.45,
|
18
|
+
'String',
|
19
|
+
[ :Symbol, ':Symbol' ],
|
20
|
+
].each do | x |
|
21
|
+
x, str = *x
|
22
|
+
str ||= x.to_s
|
23
|
+
str = "--- #{str}\n"
|
24
|
+
str << "...\n" if RUBY_VERSION !~ /^1\.8/
|
25
|
+
basic_objs << [ x, str ]
|
26
|
+
it "should handle #{x.inspect}" do
|
27
|
+
out = @enc.prepare.encode(x)
|
28
|
+
out.should == str
|
29
|
+
@dec.prepare.decode(out).should == x
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should handle :never_binary.' do
|
34
|
+
@enc.yaml_options = { :never_binary => true }
|
35
|
+
out = do_message
|
36
|
+
out.should =~ /^ :ascii_8bit: hostname/m
|
37
|
+
case RUBY_VERSION
|
38
|
+
when /^1\.8/
|
39
|
+
out.should =~ /^ :binary: !binary /m
|
40
|
+
else
|
41
|
+
out.should =~ /^ :binary: ! "\\x04/m
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should handle :ascii_8bit_ok.' do
|
46
|
+
@enc.yaml_options = { :ASCII_8BIT_ok => true }
|
47
|
+
out = do_message
|
48
|
+
out.should =~ /^ :ascii_8bit: hostname/m
|
49
|
+
out.should =~ /^ :binary: !binary /m
|
50
|
+
end
|
51
|
+
|
52
|
+
def do_message
|
53
|
+
rcvr = "String"
|
54
|
+
sel = :eval
|
55
|
+
args = [ "2 + 2" ]
|
56
|
+
msg = ASIR::Message.new(rcvr, sel, args, nil, nil)
|
57
|
+
str = 'hostname'
|
58
|
+
if str.respond_to?(:force_encoding)
|
59
|
+
str = str.force_encoding("ASCII-8BIT")
|
60
|
+
end
|
61
|
+
msg[:ascii_8bit] = str
|
62
|
+
str = Marshal.dump(@dec)
|
63
|
+
if str.respond_to?(:encoding)
|
64
|
+
str.encoding.inspect.should == "#<Encoding:ASCII-8BIT>"
|
65
|
+
end
|
66
|
+
msg[:binary] = str
|
67
|
+
msg[:source_backtrace] = caller
|
68
|
+
out = @enc.prepare.encode(msg)
|
69
|
+
end
|
70
|
+
|
71
|
+
if ''.methods.include?(:force_encoding)
|
72
|
+
it 'should extend Psych with :never_binary option.' do
|
73
|
+
require 'socket'
|
74
|
+
hostname = Socket.gethostname
|
75
|
+
enc = hostname.encoding
|
76
|
+
enc.inspect.should == "#<Encoding:ASCII-8BIT>"
|
77
|
+
|
78
|
+
str = enc.inspect
|
79
|
+
str.force_encoding(hostname.encoding)
|
80
|
+
str.encoding.inspect.should == "#<Encoding:ASCII-8BIT>"
|
81
|
+
|
82
|
+
yaml = ::YAML.dump(str)
|
83
|
+
yaml.should == "--- !binary |-\n IzxFbmNvZGluZzpBU0NJSS04QklUPg==\n"
|
84
|
+
|
85
|
+
yaml = ::YAML.dump(str, nil, :never_binary => true)
|
86
|
+
yaml.should == "--- ! '#<Encoding:ASCII-8BIT>'\n"
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should handle :never_binary options.' do
|
90
|
+
str = '8bitascii'.force_encoding('ASCII-8BIT')
|
91
|
+
|
92
|
+
@enc.yaml_options = @dec.yaml_options = nil
|
93
|
+
out = @enc.prepare.encode(str)
|
94
|
+
out.should == "--- !binary |-\n OGJpdGFzY2lp\n"
|
95
|
+
@dec.prepare.decode(str).should == str
|
96
|
+
|
97
|
+
@enc.yaml_options = { :never_binary => true }
|
98
|
+
@dec.yaml_options = @enc.yaml_options
|
99
|
+
out = @enc.prepare.encode(str)
|
100
|
+
out.should == "--- 8bitascii\n...\n"
|
101
|
+
inp = @dec.prepare.decode(str)
|
102
|
+
inp.should == str
|
103
|
+
inp.encoding.inspect.should == "#<Encoding:UTF-8>"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
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.1.
|
4
|
+
version: 1.1.5
|
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-12-
|
12
|
+
date: 2012-12-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: uuid
|
@@ -297,6 +297,7 @@ files:
|
|
297
297
|
- spec/thread_variable_spec.rb
|
298
298
|
- spec/transport_spec.rb
|
299
299
|
- spec/xml_spec.rb
|
300
|
+
- spec/yaml_spec.rb
|
300
301
|
- stylesheets/slides.css
|
301
302
|
homepage: http://github.com/kstephens/abstracting_services_in_ruby
|
302
303
|
licenses: []
|
@@ -313,7 +314,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
313
314
|
version: '0'
|
314
315
|
segments:
|
315
316
|
- 0
|
316
|
-
hash: -
|
317
|
+
hash: -3496337274665454137
|
317
318
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
318
319
|
none: false
|
319
320
|
requirements:
|
@@ -322,7 +323,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
322
323
|
version: '0'
|
323
324
|
segments:
|
324
325
|
- 0
|
325
|
-
hash: -
|
326
|
+
hash: -3496337274665454137
|
326
327
|
requirements: []
|
327
328
|
rubyforge_project:
|
328
329
|
rubygems_version: 1.8.24
|
@@ -342,3 +343,4 @@ test_files:
|
|
342
343
|
- spec/thread_variable_spec.rb
|
343
344
|
- spec/transport_spec.rb
|
344
345
|
- spec/xml_spec.rb
|
346
|
+
- spec/yaml_spec.rb
|