RFC7159 7159.01 → 7159.02

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: 2ee68a25f2005231c7cba17030c5539069884a3e
4
- data.tar.gz: 5d1b3e304935a20d83a968df182b601781bb532f
3
+ metadata.gz: 2e910977da997d84884b1f1a3dae907e8c543d70
4
+ data.tar.gz: 9edf0e2b913b74d078e93a3c4cfa58e9a5a73b76
5
5
  SHA512:
6
- metadata.gz: 671c63df9569a92d6a61b6abaae27727bd4c329c67d92fbf8e834b3cd15e1693bf2736244efabb1e79f02b09d62109b4dda0d51d2710eb3e9652d555f0a5c49a
7
- data.tar.gz: 4c743e0d39b6fbc7f21af08390445a07caf81d5ccb62675a84467653e54d6dfa130e3d1de715040e652a21a1c6c317e1fb175d532fe5daf2967931dc2c689d0e
6
+ metadata.gz: a646673c77c7dfbc323b4d209b8b7e20df11472703a969109b485dec89773dd08e3aec5761127ed806f86125177c59706bee7c75f951f3c741841b7279c667c4
7
+ data.tar.gz: abb05b7db6b343b42fa7b35dacac32f9a6ea0f7885daeb89ecadec32080fea46e9faf093a34c48849554ab8fc1afbc75782f78df3251c3f4f4c4487d5d02fc08
data/Gemfile CHANGED
@@ -33,7 +33,7 @@
33
33
 
34
34
  begin
35
35
  source 'https://rubygems.org'
36
- gemspec
36
+ gemspec require: false
37
37
 
38
38
  rescue Bundler::GemspecError
39
39
  # HACK: in order to use bundler we need a valid gemspec, and a valid gemspec
@@ -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 = port
43
- @bag = Hash.new
44
- @pp = PrettyPrint.new @port
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
- ensure_unique obj2
65
- @pp.group 1, '[', ']' do
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
- ensure_unique obj2
74
- @pp.group 1, '{', '}' do
75
- obj2.each_pair.with_index do |(i, j), k|
76
- @pp.text ',' if k > 0
77
- @pp.breakable ''
78
- case i
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
@@ -34,7 +34,7 @@
34
34
  require_relative '../RFC7159'
35
35
 
36
36
  # The version
37
- RFC7159::VERSION = 7159.01
37
+ RFC7159::VERSION = 7159.02
38
38
 
39
39
  #
40
40
  # Local Variables:
@@ -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
- {'1'=>1} => '{"1":1}',
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,
@@ -33,6 +33,7 @@
33
33
 
34
34
  ENV['RACK_ENV'] = 'test'
35
35
  require 'bundler/setup'
36
+ require 'rspec'
36
37
  require 'simplecov'
37
38
 
38
39
  RSpec.configure do |c|
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.01'
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: 2014-05-16 00:00:00.000000000 Z
12
+ date: 2015-01-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler