tidy_json 0.5.0 → 0.5.2
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 +4 -4
- data/.yardopts +0 -1
- data/Gemfile +2 -0
- data/LICENSE +1 -1
- data/README.md +6 -6
- data/bin/jtidy +8 -8
- data/bin/jtidy_info.rb +3 -6
- data/lib/tidy_json/formatter.rb +7 -14
- data/lib/tidy_json/serializer.rb +88 -19
- data/lib/tidy_json/version.rb +1 -1
- data/test/JsonableObject.json +1 -1
- data/test/test_tidy_json.rb +19 -15
- data/tidy_json.gemspec +3 -8
- metadata +7 -55
- data/lib/tidy_json/dedication.rb +0 -20
data/test/test_tidy_json.rb
CHANGED
@@ -11,11 +11,11 @@ class Nested
|
|
11
11
|
attr_accessor :a, :b, :c, :d, :e
|
12
12
|
|
13
13
|
def initialize
|
14
|
-
@a = [[], [[5, 6, 7]], [1, 2, {
|
15
|
-
@b = {
|
16
|
-
@c = [[1, 2, 3, [4]], {
|
17
|
-
@d = [{}, [], [1, 2, 3, [4]], {
|
18
|
-
@e = [[1, 2, 3, [4]], {
|
14
|
+
@a = [[], [[5, 6, 7]], [1, 2, { three: 3, four: [5, 6] }, [4]], { inner: 1 }]
|
15
|
+
@b = { a: [5], b: [1, 2, 3, [4]], c: [5], d: { inner: 1 }, e: [6] }
|
16
|
+
@c = [[1, 2, 3, [4]], { inner: 1 }, {}]
|
17
|
+
@d = [{}, [], [1, 2, 3, [4]], { inner: 1 }, []]
|
18
|
+
@e = [[1, 2, 3, [4]], { inner: 1 }, {}]
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -25,8 +25,8 @@ class JsonableObject
|
|
25
25
|
def initialize
|
26
26
|
@h = { one: 'uno', two: 'dos', three: %w[eine zwei drei], cuatro: ['I', 'II', 'III', ['i.', 'ii.', 'iii.', 'iv.']] }
|
27
27
|
@a = ['k', 'l', %w[M N O P], 'q', 'r', 's', [10, 456, ['<abbr title="Reel 2, Dialog Track 2">R2D2</abbr>', 'R', 2, 'D', ['two']]], 'u', 'v', 'x', 'y', %w[Z AB]]
|
28
|
-
@b = [{
|
29
|
-
@c = [[Nested.new, [Nested.new], [Nested.new]]]
|
28
|
+
@b = [{ uno: Nested.new }, [Nested.new, [[Nested.new], Nested.new, Nested.new], [Nested.new]]]
|
29
|
+
@c = [[Nested.new, [Nested.new, [Nested.new]], [Nested.new]]]
|
30
30
|
@d = []
|
31
31
|
@f = {}
|
32
32
|
end
|
@@ -64,13 +64,13 @@ class TidyJsonTest < Test::Unit::TestCase
|
|
64
64
|
assert_equal([{ a: 1 }, { b: 2 }, { c: 3, d: { a: 9, f: 56, i: '34', ii: '35' } }],
|
65
65
|
TidyJson.sort_keys(hash_array))
|
66
66
|
assert_equal({ a: 'one', b: 'two', c: 3 },
|
67
|
-
TidyJson.sort_keys(
|
67
|
+
TidyJson.sort_keys(b: 'two', c: 3, a: 'one'))
|
68
68
|
assert_equal([], TidyJson.sort_keys([]), 'return empty arrays unchanged')
|
69
69
|
assert_equal({}, TidyJson.sort_keys({}), 'return empty hashes unchanged')
|
70
70
|
assert_equal([3, 2, 1], TidyJson.sort_keys([3, 2, 1]),
|
71
71
|
'return arrays of keyless objects unchanged')
|
72
72
|
assert_equal([{ b: 'two' }, 'one'],
|
73
|
-
TidyJson.sort_keys([{
|
73
|
+
TidyJson.sort_keys([{ b: 'two' }, 'one']),
|
74
74
|
'arrays with any keyless objects should be returned unchanged')
|
75
75
|
end
|
76
76
|
|
@@ -82,25 +82,29 @@ class TidyJsonTest < Test::Unit::TestCase
|
|
82
82
|
assert_equal("[\n {\n \"a\": 1\n },\n {\n \"b\": 2\n },\n {\n \"c\": 3,\n \"d\": {\n \"a\": 9,\n \"f\": 56,\n \"i\": \"34\",\n \"ii\": \"35\"\n }\n }\n]\n",
|
83
83
|
nested_hash_array.to_tidy_json(indent: 8, sort: true))
|
84
84
|
assert_equal("{\n \"a\": \"one\",\n \"b\": \"two\",\n \"c\": 3\n}\n",
|
85
|
-
{
|
85
|
+
{ b: 'two', c: 3, a: 'one' }.to_tidy_json(indent: 6, sort: true))
|
86
86
|
assert_equal("[]\n", [].to_tidy_json(sort: true))
|
87
87
|
assert_equal("{}\n", {}.to_tidy_json(sort: true))
|
88
88
|
assert_equal("[\n 3,\n 2,\n 1\n]\n",
|
89
89
|
[3, 2, 1].to_tidy_json(indent: 8, sort: true))
|
90
90
|
assert_equal("[\n {\n \"b\": \"two\"\n },\n \"one\"\n]\n",
|
91
|
-
[{
|
91
|
+
[{ b: 'two' }, 'one'].to_tidy_json(indent: 4, sort: true))
|
92
92
|
end
|
93
93
|
|
94
94
|
def test_tidy_instance
|
95
95
|
assert_equal({}.to_tidy_json, "{}\n")
|
96
96
|
assert_equal([].to_tidy_json, "[]\n")
|
97
97
|
assert_equal(String.new.to_tidy_json, "\"\"\n")
|
98
|
-
assert_equal(JsonableObject.new.to_tidy_json.length,
|
98
|
+
assert_equal(JsonableObject.new.to_tidy_json.length, 17_774)
|
99
99
|
end
|
100
100
|
|
101
101
|
def test_stringify_instance
|
102
|
-
File.
|
103
|
-
|
102
|
+
output = @t.write_json(File.join(__dir__, @t.class.name))
|
103
|
+
assert(File.exist?(output))
|
104
|
+
File.open(output, 'r:UTF-8') do |json|
|
105
|
+
text = json.read.strip
|
106
|
+
assert_equal(@t.stringify, text)
|
107
|
+
assert_no_match(/(#<Nested:0x)[a-z0-9]+>/, text, 'Some objects were not serialized!')
|
104
108
|
end
|
105
109
|
rescue Errno::ENOENT, Errno::EACCES, IOError => e
|
106
110
|
flunk "#{__FILE__}.#{__LINE__}: #{e.message}"
|
@@ -132,7 +136,7 @@ class TidyJsonTest < Test::Unit::TestCase
|
|
132
136
|
|
133
137
|
def test_indent_bounds_checking
|
134
138
|
assert_equal("{\n \"a\": \"one\",\n \"b\": \"two\",\n \"c\": 3\n}\n",
|
135
|
-
{
|
139
|
+
{ b: 'two', c: 3, a: 'one' }.to_tidy_json(indent: 5, sort: true),
|
136
140
|
'odd values should fall back to default of 2')
|
137
141
|
assert_equal([].to_tidy_json(indent: '16'), "[]\n",
|
138
142
|
'values > 12 should fall back to default of 2')
|
data/tidy_json.gemspec
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'lib/tidy_json/version'
|
4
|
-
require_relative 'lib/tidy_json/dedication'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
6
|
spec.name = 'tidy_json'
|
8
7
|
spec.version = TidyJson::VERSION
|
9
|
-
spec.date = Time.now.to_s[0..9]
|
10
8
|
spec.summary = 'Serialize any Ruby object as readable JSON'
|
11
9
|
spec.description = 'A mixin providing (recursive) JSON serialization and pretty printing.'
|
12
10
|
spec.authors = ['Robert Di Pardo']
|
@@ -14,19 +12,16 @@ Gem::Specification.new do |spec|
|
|
14
12
|
spec.homepage = 'https://github.com/rdipardo/tidy_json'
|
15
13
|
spec.license = 'MIT'
|
16
14
|
spec.metadata = {
|
17
|
-
'documentation_uri' => 'https://rubydoc.
|
15
|
+
'documentation_uri' => 'https://rubydoc.info/github/rdipardo/tidy_json',
|
18
16
|
'bug_tracker_uri' => 'https://github.com/rdipardo/tidy_json/issues'
|
19
17
|
}
|
20
18
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
-
['.yardopts'].concat(`git ls-files -z`.split("\x0").reject { |f| f.match(/^(\.[\w
|
19
|
+
['.yardopts'].concat(`git ls-files -z`.split("\x0").reject { |f| f.match(/^(\.[\w+.]+|test|spec|features|codecov)/) })
|
22
20
|
end
|
23
21
|
spec.test_files = Dir['test/*']
|
24
22
|
spec.require_paths = ['lib']
|
25
23
|
spec.executables = ['jtidy']
|
26
24
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.3')
|
27
|
-
spec.add_runtime_dependency 'json', '~> 2.
|
28
|
-
spec.add_development_dependency 'test-unit', '~> 3.4'
|
29
|
-
spec.add_development_dependency 'yard', '~> 0.9'
|
25
|
+
spec.add_runtime_dependency 'json', '~> 2.6'
|
30
26
|
spec.rdoc_options = ['-x test/*']
|
31
|
-
spec.post_install_message = TidyJson::DEDICATION
|
32
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tidy_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Di Pardo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -16,42 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.6'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: test-unit
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '3.4'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '3.4'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: yard
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0.9'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0.9'
|
26
|
+
version: '2.6'
|
55
27
|
description: A mixin providing (recursive) JSON serialization and pretty printing.
|
56
28
|
email: dipardo.r@gmail.com
|
57
29
|
executables:
|
@@ -67,7 +39,6 @@ files:
|
|
67
39
|
- bin/jtidy
|
68
40
|
- bin/jtidy_info.rb
|
69
41
|
- lib/tidy_json.rb
|
70
|
-
- lib/tidy_json/dedication.rb
|
71
42
|
- lib/tidy_json/formatter.rb
|
72
43
|
- lib/tidy_json/serializer.rb
|
73
44
|
- lib/tidy_json/version.rb
|
@@ -79,27 +50,9 @@ homepage: https://github.com/rdipardo/tidy_json
|
|
79
50
|
licenses:
|
80
51
|
- MIT
|
81
52
|
metadata:
|
82
|
-
documentation_uri: https://rubydoc.
|
53
|
+
documentation_uri: https://rubydoc.info/github/rdipardo/tidy_json
|
83
54
|
bug_tracker_uri: https://github.com/rdipardo/tidy_json/issues
|
84
|
-
post_install_message:
|
85
|
-
|
86
|
-
....................................................
|
87
|
-
.............. This gem is dedicated ...............
|
88
|
-
................. to the memory of .................
|
89
|
-
....................................................
|
90
|
-
................. MICHAEL DI PARDO .................
|
91
|
-
....................................................
|
92
|
-
............ Please consider supporting ............
|
93
|
-
........... multiple sclerosis research: ...........
|
94
|
-
....................................................
|
95
|
-
....................... (US) .......................
|
96
|
-
..... https://www.nationalmssociety.org/Donate .....
|
97
|
-
..................... (Canada) .....................
|
98
|
-
........ https://mssociety.ca/get-involved .........
|
99
|
-
....................... (UK) .......................
|
100
|
-
.... https://www.mssociety.org.uk/get-involved .....
|
101
|
-
....................................................
|
102
|
-
|
55
|
+
post_install_message:
|
103
56
|
rdoc_options:
|
104
57
|
- "-x test/*"
|
105
58
|
require_paths:
|
@@ -115,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
68
|
- !ruby/object:Gem::Version
|
116
69
|
version: '0'
|
117
70
|
requirements: []
|
118
|
-
rubygems_version: 3.
|
71
|
+
rubygems_version: 3.3.15
|
119
72
|
signing_key:
|
120
73
|
specification_version: 4
|
121
74
|
summary: Serialize any Ruby object as readable JSON
|
@@ -123,4 +76,3 @@ test_files:
|
|
123
76
|
- test/JsonableObject.json
|
124
77
|
- test/codecov_runner.rb
|
125
78
|
- test/test_tidy_json.rb
|
126
|
-
...
|
data/lib/tidy_json/dedication.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module TidyJson # :nodoc:
|
4
|
-
DEDICATION = "\n#{'.' * 52}\n" \
|
5
|
-
"#{'.' * 14} This gem is dedicated " \
|
6
|
-
"#{'.' * 15}\n" \
|
7
|
-
"#{'.' * 17} to the memory of #{'.' * 17}\n#{'.' * 52}\n" \
|
8
|
-
"#{'.' * 17} MICHAEL DI PARDO #{'.' * 17}\n#{'.' * 52}\n" \
|
9
|
-
"#{'.' * 12} Please consider supporting #{'.' * 12}\n" \
|
10
|
-
"#{'.' * 11} multiple sclerosis research: #{'.' * 11}\n" \
|
11
|
-
"#{'.' * 52}\n" \
|
12
|
-
"#{'.' * 23} (US) #{'.' * 23}\n" \
|
13
|
-
"#{'.' * 5} https://www.nationalmssociety.org/Donate " \
|
14
|
-
"#{'.' * 5}\n" \
|
15
|
-
"#{'.' * 21} (Canada) #{'.' * 21}\n" \
|
16
|
-
"#{'.' * 8} https://mssociety.ca/get-involved #{'.' * 9}\n" \
|
17
|
-
"#{'.' * 23} (UK) #{'.' * 23}\n" \
|
18
|
-
"#{'.' * 4} https://www.mssociety.org.uk/get-involved "\
|
19
|
-
"#{'.' * 5}\n#{'.' * 52}\n\n"
|
20
|
-
end
|