RFC7159 7159.01 → 7159.02
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/lib/RFC7159/dumper.rb +35 -24
- data/lib/RFC7159/version.rb +1 -1
- data/spec/RFC7159_spec.rb +6 -5
- data/spec/spec_helper.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e910977da997d84884b1f1a3dae907e8c543d70
|
4
|
+
data.tar.gz: 9edf0e2b913b74d078e93a3c4cfa58e9a5a73b76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a646673c77c7dfbc323b4d209b8b7e20df11472703a969109b485dec89773dd08e3aec5761127ed806f86125177c59706bee7c75f951f3c741841b7279c667c4
|
7
|
+
data.tar.gz: abb05b7db6b343b42fa7b35dacac32f9a6ea0f7885daeb89ecadec32080fea46e9faf093a34c48849554ab8fc1afbc75782f78df3251c3f4f4c4487d5d02fc08
|
data/Gemfile
CHANGED
data/lib/RFC7159/dumper.rb
CHANGED
@@ -38,10 +38,11 @@ require 'prettyprint'
|
|
38
38
|
class RFC7159::Dumper
|
39
39
|
|
40
40
|
# @param [#<<] port output destination
|
41
|
-
def initialize port
|
42
|
-
@port
|
43
|
-
@bag
|
44
|
-
@
|
41
|
+
def initialize port, indent = 4
|
42
|
+
@port = port
|
43
|
+
@bag = Hash.new
|
44
|
+
@indent = indent
|
45
|
+
@pp = PrettyPrint.new @port
|
45
46
|
@bag.compare_by_identity
|
46
47
|
end
|
47
48
|
|
@@ -61,29 +62,19 @@ class RFC7159::Dumper
|
|
61
62
|
obj2 = try_convert obj
|
62
63
|
case obj2
|
63
64
|
when ::Array, RFC7159::Array then
|
64
|
-
|
65
|
-
|
66
|
-
obj2.each.with_index do |i, j|
|
67
|
-
@pp.text ',' if j > 0
|
68
|
-
@pp.breakable ''
|
69
|
-
dump i
|
70
|
-
end
|
65
|
+
js_group obj2, :each, '[', ']' do |i|
|
66
|
+
dump i
|
71
67
|
end
|
72
68
|
when ::Hash, RFC7159::Object then
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
when ::String, RFC7159::String
|
80
|
-
dump i
|
81
|
-
else
|
82
|
-
dump i.to_str # should raise for non-string-ish
|
83
|
-
end
|
84
|
-
@pp.text ':'
|
85
|
-
dump j
|
69
|
+
js_group obj2, :each_pair, '{', '}' do |(i, j)|
|
70
|
+
case i
|
71
|
+
when ::String, RFC7159::String
|
72
|
+
dump i
|
73
|
+
else
|
74
|
+
dump i.to_str # should raise for non-string-ish
|
86
75
|
end
|
76
|
+
@pp.text ': '
|
77
|
+
dump j
|
87
78
|
end
|
88
79
|
when RFC7159::Value then
|
89
80
|
obj3 = obj2.to_json
|
@@ -126,6 +117,26 @@ class RFC7159::Dumper
|
|
126
117
|
end
|
127
118
|
end
|
128
119
|
|
120
|
+
# much like PP#object_group, except that it indents like JSON.
|
121
|
+
def js_group obj, method, open, close
|
122
|
+
ensure_unique obj
|
123
|
+
enum = obj.send method
|
124
|
+
@pp.text open
|
125
|
+
@pp.group_sub do
|
126
|
+
@pp.nest @indent do
|
127
|
+
enum.with_index do |a, i|
|
128
|
+
if i > 0
|
129
|
+
@pp.text ','
|
130
|
+
end
|
131
|
+
@pp.breakable ' '
|
132
|
+
yield a
|
133
|
+
end
|
134
|
+
end
|
135
|
+
@pp.breakable ' '
|
136
|
+
end
|
137
|
+
@pp.text close
|
138
|
+
end
|
139
|
+
|
129
140
|
def try_convert obj
|
130
141
|
case obj
|
131
142
|
when RFC7159::Value, Hash, Array, String, Integer, Float, BigDecimal, TrueClass, FalseClass, NilClass
|
data/lib/RFC7159/version.rb
CHANGED
data/spec/RFC7159_spec.rb
CHANGED
@@ -107,11 +107,12 @@ describe RFC7159 do
|
|
107
107
|
"\u{dead}" => '"\\uDEAD"', # invalid UTF8 to be valid escaped UTF8
|
108
108
|
'foo'.encode('utf-32le') => '"foo"',
|
109
109
|
"\xDE\xAD".force_encoding('utf-16be') => '"\\uDEAD"',
|
110
|
-
[] => '[]',
|
111
|
-
[0] => '[0]',
|
112
|
-
|
113
|
-
{
|
114
|
-
{''=>
|
110
|
+
[] => '[ ]',
|
111
|
+
[0] => '[ 0 ]',
|
112
|
+
[0,1] => '[ 0, 1 ]',
|
113
|
+
{} => '{ }',
|
114
|
+
{'1'=>1} => '{ "1": 1 }',
|
115
|
+
{''=>''} => '{ "": "" }',
|
115
116
|
(0.0/0.0) => false,
|
116
117
|
(1.0/0.0) => false,
|
117
118
|
BigDecimal("NaN") => false,
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: RFC7159
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '7159.
|
4
|
+
version: '7159.02'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Urabe,
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-01-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|