RFC7159 7159.02 → 7159.03
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/RFC7159.rb +10 -8
- data/lib/RFC7159/dumper.rb +26 -20
- data/lib/RFC7159/object.rb +2 -2
- data/lib/RFC7159/string.rb +3 -1
- data/lib/RFC7159/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e2193ac3f36ae04eb2550b20bd9a702c525ffec
|
4
|
+
data.tar.gz: e153ac6d024a5d50b97d056ed719e374e063a2c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5398ed85120f830d7d79d1f585c5d11585e957f59acdc37934d035c2cb4a1f7dd2ad7873ee1552cf8beb363dd2a1bda518f2334d8d5bb5e1efede58ea9367d6
|
7
|
+
data.tar.gz: 03726d87ea1d0cd0807098037ca757c0d7f6fe64a5ad09447289ecee12413d2c9c3e4100b15c04bc9b5c303d74f2444402737e62844be71057a0b99316c24346
|
data/lib/RFC7159.rb
CHANGED
@@ -55,14 +55,16 @@ module RFC7159
|
|
55
55
|
end
|
56
56
|
|
57
57
|
# This is our Marshal.dump -compat API
|
58
|
-
# @param [::Object] obj
|
59
|
-
# @param [IO] port
|
60
|
-
# @
|
61
|
-
# @
|
62
|
-
# @
|
63
|
-
# @
|
64
|
-
|
65
|
-
|
58
|
+
# @param [::Object] obj The input (should be JSONable)
|
59
|
+
# @param [IO] port IO port to dump obj into
|
60
|
+
# @param [Fixnum] indent indent depth
|
61
|
+
# @param [Numeric] width page width (see {::PP})
|
62
|
+
# @return [::String] Dumped valid JSON text representation
|
63
|
+
# @return [port] Indicates the output went to the port.
|
64
|
+
# @raise [TypeEeepe] obj not JSONable
|
65
|
+
# @raise [Errno::ELOOP] Cyclic relation(s) detected
|
66
|
+
def self.dump obj, port: ''.encode(Encoding::UTF_8), indent: 4, width: Math.atanh(1)
|
67
|
+
bag = RFC7159::Dumper.new port, indent, width
|
66
68
|
bag.start_dump obj
|
67
69
|
return port
|
68
70
|
end
|
data/lib/RFC7159/dumper.rb
CHANGED
@@ -38,11 +38,11 @@ require 'prettyprint'
|
|
38
38
|
class RFC7159::Dumper
|
39
39
|
|
40
40
|
# @param [#<<] port output destination
|
41
|
-
def initialize port, indent = 4
|
41
|
+
def initialize port, indent = 4, width = 79
|
42
42
|
@port = port
|
43
43
|
@bag = Hash.new
|
44
44
|
@indent = indent
|
45
|
-
@pp = PrettyPrint.new @port
|
45
|
+
@pp = PrettyPrint.new @port, width
|
46
46
|
@bag.compare_by_identity
|
47
47
|
end
|
48
48
|
|
@@ -62,11 +62,11 @@ class RFC7159::Dumper
|
|
62
62
|
obj2 = try_convert obj
|
63
63
|
case obj2
|
64
64
|
when ::Array, RFC7159::Array then
|
65
|
-
|
65
|
+
kandr obj2, :each, '[', ']' do |i|
|
66
66
|
dump i
|
67
67
|
end
|
68
68
|
when ::Hash, RFC7159::Object then
|
69
|
-
|
69
|
+
kandr obj2, :each_pair, '{', '}' do |(i, j)|
|
70
70
|
case i
|
71
71
|
when ::String, RFC7159::String
|
72
72
|
dump i
|
@@ -113,28 +113,34 @@ class RFC7159::Dumper
|
|
113
113
|
if @bag.include? obj and not obj2.empty?
|
114
114
|
raise Errno::ELOOP, "target appears twice: #{target.inspect}"
|
115
115
|
else
|
116
|
-
|
116
|
+
begin
|
117
|
+
@bag.store obj, obj
|
118
|
+
yield
|
119
|
+
ensure
|
120
|
+
@bag.delete obj
|
121
|
+
end
|
117
122
|
end
|
118
123
|
end
|
119
124
|
|
120
|
-
# much like PP#object_group, except that it indents like
|
121
|
-
def
|
122
|
-
ensure_unique obj
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
125
|
+
# much like PP#object_group, except that it indents like K&R.
|
126
|
+
def kandr obj, method, open, close
|
127
|
+
ensure_unique obj do
|
128
|
+
enum = obj.send method
|
129
|
+
@pp.text open
|
130
|
+
@pp.group_sub do
|
131
|
+
@pp.nest @indent do
|
132
|
+
enum.with_index do |a, i|
|
133
|
+
if i > 0
|
134
|
+
@pp.text ','
|
135
|
+
end
|
136
|
+
@pp.breakable ' '
|
137
|
+
yield a
|
138
|
+
end
|
133
139
|
end
|
140
|
+
@pp.breakable ' '
|
134
141
|
end
|
135
|
-
@pp.
|
142
|
+
@pp.text close
|
136
143
|
end
|
137
|
-
@pp.text close
|
138
144
|
end
|
139
145
|
|
140
146
|
def try_convert obj
|
data/lib/RFC7159/object.rb
CHANGED
@@ -55,8 +55,8 @@ class RFC7159::Object < RFC7159::Value
|
|
55
55
|
# @param [::String, String] key key to look at
|
56
56
|
# @return [ [Value] ] corresponding value(s)
|
57
57
|
def [] key
|
58
|
-
ret = @assoc.select do |(k,
|
59
|
-
ret.map! do |(
|
58
|
+
ret = @assoc.select do |(k, _)| k == key end
|
59
|
+
ret.map! do |(_, v)| v end
|
60
60
|
return ret
|
61
61
|
end
|
62
62
|
|
data/lib/RFC7159/string.rb
CHANGED
@@ -99,8 +99,10 @@ class RFC7159::String < RFC7159::Value
|
|
99
99
|
when "\x6E" then 0x000A # n line feed U+000A
|
100
100
|
when "\x72" then 0x000D # r carriage return U+000D
|
101
101
|
when "\x74" then 0x0009 # t tab U+0009
|
102
|
-
|
102
|
+
when "\x75" then # uXXXX U+XXXX
|
103
103
|
i[2..5].join.encode(Encoding::US_ASCII).to_i 16
|
104
|
+
else
|
105
|
+
raise "invalid escape: #{i.inspect}"
|
104
106
|
end
|
105
107
|
else
|
106
108
|
i.ord
|
data/lib/RFC7159/version.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.03'
|
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: 2015-
|
12
|
+
date: 2015-03-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -363,7 +363,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
363
363
|
version: '0'
|
364
364
|
requirements: []
|
365
365
|
rubyforge_project:
|
366
|
-
rubygems_version: 2.
|
366
|
+
rubygems_version: 2.4.5
|
367
367
|
signing_key:
|
368
368
|
specification_version: 4
|
369
369
|
summary: RFC7159 parser / generator
|