lazy-pp-json 0.0.1
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 +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +50 -0
- data/Rakefile +8 -0
- data/bin/lazy-pp-json +16 -0
- data/lazy-pp-json.gemspec +45 -0
- data/lib/lazy-pp-json.rb +3 -0
- data/lib/lazy/pp/json.rb +145 -0
- data/lib/lazy/pp/json/version.rb +9 -0
- data/test/run-test.rb +24 -0
- data/test/test_array.rb +133 -0
- data/test/test_hash.rb +79 -0
- data/test/testutils.rb +42 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 813e7d8a61cb2d7dbe7693f20033d4d8ccf1cb02
|
4
|
+
data.tar.gz: 8dec269665ec388bb077b2ff97e8a5d83325a501
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f0eca7b147491108e5ad76a9f918cf62fcb5c9249c02503672336906a17005f35d1eea7c179a905a1ef9fe8c58d0fc5b2446eed72f2300086755865efcf7021f
|
7
|
+
data.tar.gz: e88ca1a75310e13ba97359dadccee1e76fb27ecf42fe7f04487fe2f7e8fab205b9a545ab56a766f6b8b56bb445a73dd6af00ce4d982e82d33f590015b55a6966
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 yoshihara
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# lazy-pp-json
|
2
|
+
|
3
|
+
[](https://travis-ci.org/yoshihara/lazy-pp-json)
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
Lazy pp json responses.
|
8
|
+
|
9
|
+
### Normal pp
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
pp JSON.parse('{"key1":{"key1-1":"value1-1","key1-2":"value1-2"}, "key2":"value2"}')
|
13
|
+
#=> {"key1"=>{"key1-1"=>"value1-1", "key1-2"=>"value1-2"}, "key2"=>"value2"}
|
14
|
+
```
|
15
|
+
|
16
|
+
### lazy-pp-json
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
pp Lazy::PP::JSON.new('{"key1":{"key1-1":"value1-1","key1-2":"value1-2"}, "key2":"value2"}')
|
20
|
+
#=>
|
21
|
+
# {
|
22
|
+
# "key1":
|
23
|
+
# {
|
24
|
+
# "key1-1":"value1-1",
|
25
|
+
# "key1-2":"value1-2"
|
26
|
+
# },
|
27
|
+
# "key2":"value2"
|
28
|
+
# }
|
29
|
+
#
|
30
|
+
```
|
31
|
+
|
32
|
+
## Installation
|
33
|
+
|
34
|
+
$ gem install lazy-pp-json
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
require "lazy-pp-json"
|
40
|
+
|
41
|
+
pp Lazy::PP::JSON.new(json_string)
|
42
|
+
```
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
1. Fork it
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/lazy-pp-json
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8; mode: ruby -*-
|
3
|
+
|
4
|
+
require "lazy-pp-json"
|
5
|
+
|
6
|
+
if ARGV.size > 1
|
7
|
+
puts <<DESCRIPTION
|
8
|
+
error: lazy-pp-json should have 1 argument only.
|
9
|
+
|
10
|
+
Usage:
|
11
|
+
lazy-pp-json JSON_STRING
|
12
|
+
DESCRIPTION
|
13
|
+
exit(false)
|
14
|
+
end
|
15
|
+
|
16
|
+
pp Lazy::PP::JSON.new(ARGV.first)
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
base_dir = File.dirname(__FILE__)
|
3
|
+
$LOAD_PATH.unshift(File.expand_path("lib", base_dir))
|
4
|
+
|
5
|
+
require 'lazy/pp/json/version'
|
6
|
+
|
7
|
+
readme_path = File.join(base_dir, "README.md")
|
8
|
+
entries = File.read(readme_path).split(/^##\s(.*)$/)
|
9
|
+
entry = lambda do |entry_title|
|
10
|
+
entries[entries.index(entry_title) + 1]
|
11
|
+
end
|
12
|
+
clean_white_space = lambda do |entry|
|
13
|
+
entry.gsub(/(\A\n+|\n+\z)/, '')
|
14
|
+
end
|
15
|
+
|
16
|
+
description = clean_white_space.call(entry.call("Description"))
|
17
|
+
summary = description.gsub(/\.\n.+\Z/m ,"") + "\n"
|
18
|
+
|
19
|
+
Gem::Specification.new do |spec|
|
20
|
+
spec.name = "lazy-pp-json"
|
21
|
+
spec.version = Lazy::PP::JSON::VERSION
|
22
|
+
spec.authors = ["yoshihara"]
|
23
|
+
spec.email = ["h.yoshihara@everyleaf.com"]
|
24
|
+
spec.description = description
|
25
|
+
spec.summary = summary
|
26
|
+
spec.homepage = ""
|
27
|
+
spec.license = "MIT"
|
28
|
+
|
29
|
+
spec.files = ["README.md", "LICENSE.txt"]
|
30
|
+
spec.files += ["Rakefile", "Gemfile", "lazy-pp-json.gemspec"]
|
31
|
+
spec.files += Dir.glob("lib/**/*.rb")
|
32
|
+
spec.files += Dir.glob("doc/text/*.*")
|
33
|
+
spec.test_files = Dir.glob("test/**/*.rb")
|
34
|
+
Dir.chdir("bin") do
|
35
|
+
spec.executables = Dir.glob("*")
|
36
|
+
end
|
37
|
+
spec.require_paths = ["lib"]
|
38
|
+
|
39
|
+
spec.add_runtime_dependency "json"
|
40
|
+
|
41
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
42
|
+
spec.add_development_dependency "test-unit"
|
43
|
+
spec.add_development_dependency "test-unit-notify"
|
44
|
+
spec.add_development_dependency "rake"
|
45
|
+
end
|
data/lib/lazy-pp-json.rb
ADDED
data/lib/lazy/pp/json.rb
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require "pp"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module Lazy
|
7
|
+
module PP
|
8
|
+
class JSON < String
|
9
|
+
INDENT_SIZE = 2
|
10
|
+
INDENT = ' ' * INDENT_SIZE
|
11
|
+
MAX_CHARACTER_SIZE = 40
|
12
|
+
|
13
|
+
def initialize(raw, indent_count=nil)
|
14
|
+
super(raw)
|
15
|
+
@indent_count = indent_count || 1
|
16
|
+
@newline_separator = false
|
17
|
+
@pretty_print = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def pretty_print(pretty_print)
|
21
|
+
@pretty_print = pretty_print
|
22
|
+
object = ::JSON.parse(self)
|
23
|
+
|
24
|
+
if object.empty?
|
25
|
+
@pretty_print.pp object
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
case object
|
30
|
+
when Hash
|
31
|
+
@pretty_print.group(indent_width, "{", "}") do
|
32
|
+
first = true
|
33
|
+
object.each do |key, value|
|
34
|
+
@pretty_print.text(",") unless first
|
35
|
+
|
36
|
+
text_indent
|
37
|
+
|
38
|
+
text_key(key)
|
39
|
+
|
40
|
+
first = false
|
41
|
+
|
42
|
+
text_value(value)
|
43
|
+
end
|
44
|
+
|
45
|
+
text_prev_indent
|
46
|
+
end
|
47
|
+
|
48
|
+
when Array
|
49
|
+
@pretty_print.group(indent_width, "[", "]") do
|
50
|
+
if separate_elements_with_newline?(object)
|
51
|
+
@newline_separator = true
|
52
|
+
end
|
53
|
+
|
54
|
+
object.each.with_index do |element, i|
|
55
|
+
if i.zero?
|
56
|
+
text_indent if @newline_separator
|
57
|
+
end
|
58
|
+
|
59
|
+
text_element(element)
|
60
|
+
text_separator if i < object.length-1
|
61
|
+
end
|
62
|
+
|
63
|
+
text_prev_indent if @newline_separator
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def pretty_pring_circle(pretty_print)
|
69
|
+
pretty_print.text(empty? ? "" : "{...}")
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def json_value_format?(object)
|
75
|
+
object.instance_of?(Array) or object.instance_of?(Hash)
|
76
|
+
end
|
77
|
+
|
78
|
+
def separate_elements_with_newline?(object)
|
79
|
+
return false unless object.instance_of?(Array)
|
80
|
+
return true if object.any? {|element| json_value_format?(element) }
|
81
|
+
|
82
|
+
array_length = object.map(&:to_s).join.size + indent_width
|
83
|
+
array_length > MAX_CHARACTER_SIZE
|
84
|
+
end
|
85
|
+
|
86
|
+
def indent
|
87
|
+
" " * indent_width
|
88
|
+
end
|
89
|
+
|
90
|
+
def prev_indent
|
91
|
+
" " * prev_indent_width
|
92
|
+
end
|
93
|
+
|
94
|
+
def indent_width
|
95
|
+
INDENT_SIZE * @indent_count
|
96
|
+
end
|
97
|
+
|
98
|
+
def prev_indent_width
|
99
|
+
INDENT_SIZE * (@indent_count - 1)
|
100
|
+
end
|
101
|
+
|
102
|
+
def text_indent
|
103
|
+
@pretty_print.text "\n#{indent}"
|
104
|
+
end
|
105
|
+
|
106
|
+
def text_prev_indent
|
107
|
+
@pretty_print.text "\n#{prev_indent}"
|
108
|
+
end
|
109
|
+
|
110
|
+
def text_key(key)
|
111
|
+
@pretty_print.pp key
|
112
|
+
@pretty_print.text ":"
|
113
|
+
end
|
114
|
+
|
115
|
+
def text_value(value)
|
116
|
+
if value.instance_of?(String)
|
117
|
+
@pretty_print.pp value
|
118
|
+
return
|
119
|
+
end
|
120
|
+
|
121
|
+
text_indent if json_value_format?(value)
|
122
|
+
text_element(value)
|
123
|
+
end
|
124
|
+
|
125
|
+
def text_element(element)
|
126
|
+
element = create_next_json(element)
|
127
|
+
@pretty_print.pp element
|
128
|
+
end
|
129
|
+
|
130
|
+
def create_next_json(value)
|
131
|
+
return value if value.instance_of?(String)
|
132
|
+
JSON.new(value.to_s.gsub("=>", ":"), @indent_count + 1)
|
133
|
+
end
|
134
|
+
|
135
|
+
def text_separator
|
136
|
+
@pretty_print.text ","
|
137
|
+
if @newline_separator
|
138
|
+
text_indent
|
139
|
+
else
|
140
|
+
@pretty_print.text " "
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
data/test/run-test.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
$VERBOSE = true
|
5
|
+
|
6
|
+
base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
7
|
+
lib_dir = File.join(base_dir, "lib")
|
8
|
+
test_dir = File.join(base_dir, "test")
|
9
|
+
|
10
|
+
require "test/unit"
|
11
|
+
require "test/unit/notify"
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(lib_dir)
|
14
|
+
$LOAD_PATH.unshift(base_dir)
|
15
|
+
|
16
|
+
$LOAD_PATH.unshift(test_dir)
|
17
|
+
|
18
|
+
Dir.glob("#{base_dir}/test/**/test{_,-}*.rb") do |file|
|
19
|
+
require file.gsub(/\.rb$/, "")
|
20
|
+
end
|
21
|
+
|
22
|
+
ENV["TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"] ||= "5000"
|
23
|
+
|
24
|
+
exit(Test::Unit::AutoRunner.run)
|
data/test/test_array.rb
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require "testutils"
|
4
|
+
|
5
|
+
module Lazy
|
6
|
+
module PP
|
7
|
+
class JSON
|
8
|
+
class ArrayTest < Test::Unit::TestCase
|
9
|
+
include Lazy::PP::JSON::TestUtils
|
10
|
+
|
11
|
+
def test_empty
|
12
|
+
assert_lazy_json("[]\n", '[]')
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_short_single
|
16
|
+
assert_lazy_json('["1"]' + "\n", '["1"]')
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_long_single
|
20
|
+
assert_lazy_json(<<EXPECTED, "[\"#{LONG_STRING}\"]")
|
21
|
+
[
|
22
|
+
"#{LONG_STRING}"
|
23
|
+
]
|
24
|
+
EXPECTED
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_short_double
|
28
|
+
assert_lazy_json('["1", "2"]' + "\n", '["1", "2"]')
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_long_double
|
32
|
+
assert_lazy_json(<<EXPECTED, SPLITED_LONG_ARRAY_STRING)
|
33
|
+
[
|
34
|
+
"#{SPLITED_LONG_ARRAY.first}",
|
35
|
+
"#{SPLITED_LONG_ARRAY.last}"
|
36
|
+
]
|
37
|
+
EXPECTED
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_including_short_array
|
41
|
+
actual_string = '["first", ["1","2"], "last"]'
|
42
|
+
assert_lazy_json(<<EXPECTED, actual_string)
|
43
|
+
[
|
44
|
+
"first",
|
45
|
+
["1", "2"],
|
46
|
+
"last"
|
47
|
+
]
|
48
|
+
EXPECTED
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_including_long_array
|
52
|
+
actual_string = "[\"first\", #{SPLITED_LONG_ARRAY_STRING}, \"last\"]"
|
53
|
+
assert_lazy_json(<<EXPECTED, actual_string)
|
54
|
+
[
|
55
|
+
"first",
|
56
|
+
[
|
57
|
+
"#{SPLITED_LONG_ARRAY.first}",
|
58
|
+
"#{SPLITED_LONG_ARRAY.last}"
|
59
|
+
],
|
60
|
+
"last"
|
61
|
+
]
|
62
|
+
EXPECTED
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_including_array_including_short_array
|
66
|
+
actual_string = <<ACTUAL
|
67
|
+
["first", ["first-first", ["first-first-first", "first-first-last"]], "last"]
|
68
|
+
ACTUAL
|
69
|
+
assert_lazy_json(<<EXPECTED, actual_string)
|
70
|
+
[
|
71
|
+
"first",
|
72
|
+
[
|
73
|
+
"first-first",
|
74
|
+
["first-first-first", "first-first-last"]
|
75
|
+
],
|
76
|
+
"last"
|
77
|
+
]
|
78
|
+
EXPECTED
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_including_array_including_long_array
|
82
|
+
actual_string = <<ACTUAL
|
83
|
+
["first", ["first-first", #{SPLITED_LONG_ARRAY_STRING}, "first-last"], "last"]
|
84
|
+
ACTUAL
|
85
|
+
assert_lazy_json(<<EXPECTED, actual_string)
|
86
|
+
[
|
87
|
+
"first",
|
88
|
+
[
|
89
|
+
"first-first",
|
90
|
+
[
|
91
|
+
"#{SPLITED_LONG_ARRAY.first}",
|
92
|
+
"#{SPLITED_LONG_ARRAY.last}"
|
93
|
+
],
|
94
|
+
"first-last"
|
95
|
+
],
|
96
|
+
"last"
|
97
|
+
]
|
98
|
+
EXPECTED
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_including_hash
|
102
|
+
actual_string = <<ACTUAL
|
103
|
+
["first", {"key":"value"}, "last"]
|
104
|
+
ACTUAL
|
105
|
+
assert_lazy_json(<<EXPECTED, actual_string)
|
106
|
+
[
|
107
|
+
"first",
|
108
|
+
{
|
109
|
+
"key":"value"
|
110
|
+
},
|
111
|
+
"last"
|
112
|
+
]
|
113
|
+
EXPECTED
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_short_including_hash
|
117
|
+
actual_string = <<ACTUAL
|
118
|
+
["a", {"key":"value"}, "b"]
|
119
|
+
ACTUAL
|
120
|
+
assert_lazy_json(<<EXPECTED, actual_string)
|
121
|
+
[
|
122
|
+
"a",
|
123
|
+
{
|
124
|
+
"key":"value"
|
125
|
+
},
|
126
|
+
"b"
|
127
|
+
]
|
128
|
+
EXPECTED
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
data/test/test_hash.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require "testutils"
|
4
|
+
|
5
|
+
module Lazy
|
6
|
+
module PP
|
7
|
+
class JSON
|
8
|
+
class HashTest < Test::Unit::TestCase
|
9
|
+
include Lazy::PP::JSON::TestUtils
|
10
|
+
|
11
|
+
def test_empty
|
12
|
+
assert_lazy_json("{}\n", '{}')
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_single
|
16
|
+
assert_lazy_json(<<EXPECTED, '{"key":"value"}')
|
17
|
+
{
|
18
|
+
"key":"value"
|
19
|
+
}
|
20
|
+
EXPECTED
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_double
|
24
|
+
assert_lazy_json(<<EXPECTED, '{"key1":"value1", "key2":"value2"}')
|
25
|
+
{
|
26
|
+
"key1":"value1",
|
27
|
+
"key2":"value2"
|
28
|
+
}
|
29
|
+
EXPECTED
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_short_array_as_value
|
33
|
+
actual_string = <<ACTUAL
|
34
|
+
{"key1":["1","2"], "key2":"value2"}
|
35
|
+
ACTUAL
|
36
|
+
assert_lazy_json(<<EXPECTED, actual_string)
|
37
|
+
{
|
38
|
+
"key1":
|
39
|
+
["1", "2"],
|
40
|
+
"key2":"value2"
|
41
|
+
}
|
42
|
+
EXPECTED
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_long_array_as_value
|
46
|
+
actual_string = <<ACTUAL
|
47
|
+
{"key1":#{SPLITED_LONG_ARRAY_STRING}, "key2":"value2"}
|
48
|
+
ACTUAL
|
49
|
+
assert_lazy_json(<<EXPECTED, actual_string)
|
50
|
+
{
|
51
|
+
"key1":
|
52
|
+
[
|
53
|
+
"#{SPLITED_LONG_ARRAY.first}",
|
54
|
+
"#{SPLITED_LONG_ARRAY.last}"
|
55
|
+
],
|
56
|
+
"key2":"value2"
|
57
|
+
}
|
58
|
+
EXPECTED
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_including_hash
|
62
|
+
actual_string = <<ACTUAL
|
63
|
+
{"key1":{"key1-1":"value1-1","key1-2":"value1-2"}, "key2":"value2"}
|
64
|
+
ACTUAL
|
65
|
+
assert_lazy_json(<<EXPECTED, actual_string)
|
66
|
+
{
|
67
|
+
"key1":
|
68
|
+
{
|
69
|
+
"key1-1":"value1-1",
|
70
|
+
"key1-2":"value1-2"
|
71
|
+
},
|
72
|
+
"key2":"value2"
|
73
|
+
}
|
74
|
+
EXPECTED
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/test/testutils.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require "stringio"
|
4
|
+
require "lazy/pp/json"
|
5
|
+
|
6
|
+
module Lazy
|
7
|
+
module PP
|
8
|
+
class JSON
|
9
|
+
module TestUtils
|
10
|
+
|
11
|
+
# 52 chars
|
12
|
+
LONG_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
13
|
+
SPLITED_LONG_ARRAY = [
|
14
|
+
LONG_STRING[0..25],
|
15
|
+
LONG_STRING[26..51]
|
16
|
+
]
|
17
|
+
|
18
|
+
SPLITED_LONG_ARRAY_STRING = <<ACTUAL
|
19
|
+
["#{LONG_STRING[0..25]}", "#{LONG_STRING[26..51]}"]
|
20
|
+
ACTUAL
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@original_stdout = $stdout.dup
|
24
|
+
@stdout = StringIO.new
|
25
|
+
$stdout = @stdout
|
26
|
+
end
|
27
|
+
|
28
|
+
def teardown
|
29
|
+
$stdout = @original_stdout
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def assert_lazy_json(expected, actual_string)
|
35
|
+
actual = Lazy::PP::JSON.new(actual_string)
|
36
|
+
pp(actual)
|
37
|
+
assert_equal(expected, @stdout.string, @stdout.string)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lazy-pp-json
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- yoshihara
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: test-unit-notify
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: |-
|
84
|
+
Lazy pp json responses.
|
85
|
+
|
86
|
+
### Normal pp
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
pp JSON.parse('{"key1":{"key1-1":"value1-1","key1-2":"value1-2"}, "key2":"value2"}')
|
90
|
+
#=> {"key1"=>{"key1-1"=>"value1-1", "key1-2"=>"value1-2"}, "key2"=>"value2"}
|
91
|
+
```
|
92
|
+
|
93
|
+
### lazy-pp-json
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
pp Lazy::PP::JSON.new('{"key1":{"key1-1":"value1-1","key1-2":"value1-2"}, "key2":"value2"}')
|
97
|
+
#=>
|
98
|
+
# {
|
99
|
+
# "key1":
|
100
|
+
# {
|
101
|
+
# "key1-1":"value1-1",
|
102
|
+
# "key1-2":"value1-2"
|
103
|
+
# },
|
104
|
+
# "key2":"value2"
|
105
|
+
# }
|
106
|
+
#
|
107
|
+
```
|
108
|
+
email:
|
109
|
+
- h.yoshihara@everyleaf.com
|
110
|
+
executables:
|
111
|
+
- lazy-pp-json
|
112
|
+
extensions: []
|
113
|
+
extra_rdoc_files: []
|
114
|
+
files:
|
115
|
+
- Gemfile
|
116
|
+
- LICENSE.txt
|
117
|
+
- README.md
|
118
|
+
- Rakefile
|
119
|
+
- bin/lazy-pp-json
|
120
|
+
- lazy-pp-json.gemspec
|
121
|
+
- lib/lazy-pp-json.rb
|
122
|
+
- lib/lazy/pp/json.rb
|
123
|
+
- lib/lazy/pp/json/version.rb
|
124
|
+
- test/run-test.rb
|
125
|
+
- test/test_array.rb
|
126
|
+
- test/test_hash.rb
|
127
|
+
- test/testutils.rb
|
128
|
+
homepage: ''
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
metadata: {}
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 2.2.0
|
149
|
+
signing_key:
|
150
|
+
specification_version: 4
|
151
|
+
summary: Lazy pp json responses
|
152
|
+
test_files:
|
153
|
+
- test/run-test.rb
|
154
|
+
- test/test_array.rb
|
155
|
+
- test/test_hash.rb
|
156
|
+
- test/testutils.rb
|