RFC7159 7159.02 → 7159.03

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e910977da997d84884b1f1a3dae907e8c543d70
4
- data.tar.gz: 9edf0e2b913b74d078e93a3c4cfa58e9a5a73b76
3
+ metadata.gz: 7e2193ac3f36ae04eb2550b20bd9a702c525ffec
4
+ data.tar.gz: e153ac6d024a5d50b97d056ed719e374e063a2c2
5
5
  SHA512:
6
- metadata.gz: a646673c77c7dfbc323b4d209b8b7e20df11472703a969109b485dec89773dd08e3aec5761127ed806f86125177c59706bee7c75f951f3c741841b7279c667c4
7
- data.tar.gz: abb05b7db6b343b42fa7b35dacac32f9a6ea0f7885daeb89ecadec32080fea46e9faf093a34c48849554ab8fc1afbc75782f78df3251c3f4f4c4487d5d02fc08
6
+ metadata.gz: b5398ed85120f830d7d79d1f585c5d11585e957f59acdc37934d035c2cb4a1f7dd2ad7873ee1552cf8beb363dd2a1bda518f2334d8d5bb5e1efede58ea9367d6
7
+ data.tar.gz: 03726d87ea1d0cd0807098037ca757c0d7f6fe64a5ad09447289ecee12413d2c9c3e4100b15c04bc9b5c303d74f2444402737e62844be71057a0b99316c24346
@@ -55,14 +55,16 @@ module RFC7159
55
55
  end
56
56
 
57
57
  # This is our Marshal.dump -compat API
58
- # @param [::Object] obj The input (should be JSONable)
59
- # @param [IO] port IO port to dump obj into
60
- # @return [::String] Dumped valid JSON text representation
61
- # @return [port] Indicates the output went to the port.
62
- # @raise [TypeEeepe] obj not JSONable
63
- # @raise [Errno::ELOOP] Cyclic relation(s) detected
64
- def self.dump obj, port: ''.encode(Encoding::UTF_8)
65
- bag = RFC7159::Dumper.new port
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
@@ -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
- js_group obj2, :each, '[', ']' do |i|
65
+ kandr obj2, :each, '[', ']' do |i|
66
66
  dump i
67
67
  end
68
68
  when ::Hash, RFC7159::Object then
69
- js_group obj2, :each_pair, '{', '}' do |(i, j)|
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
- @bag.store obj, obj
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 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
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.breakable ' '
142
+ @pp.text close
136
143
  end
137
- @pp.text close
138
144
  end
139
145
 
140
146
  def try_convert obj
@@ -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, v)| k == key end
59
- ret.map! do |(k, v)| v end
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
 
@@ -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
- else "\x75" # uXXXX U+XXXX
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
@@ -34,7 +34,7 @@
34
34
  require_relative '../RFC7159'
35
35
 
36
36
  # The version
37
- RFC7159::VERSION = 7159.02
37
+ RFC7159::VERSION = 7159.03
38
38
 
39
39
  #
40
40
  # Local Variables:
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.02'
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-01-02 00:00:00.000000000 Z
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.2.2
366
+ rubygems_version: 2.4.5
367
367
  signing_key:
368
368
  specification_version: 4
369
369
  summary: RFC7159 parser / generator