lazy-pp-json 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 813e7d8a61cb2d7dbe7693f20033d4d8ccf1cb02
4
- data.tar.gz: 8dec269665ec388bb077b2ff97e8a5d83325a501
3
+ metadata.gz: 5e219c038868b87ed3a27c5845d38ac2bade011a
4
+ data.tar.gz: a15660808bc9659df9374c470e0e2d1d53904e66
5
5
  SHA512:
6
- metadata.gz: f0eca7b147491108e5ad76a9f918cf62fcb5c9249c02503672336906a17005f35d1eea7c179a905a1ef9fe8c58d0fc5b2446eed72f2300086755865efcf7021f
7
- data.tar.gz: e88ca1a75310e13ba97359dadccee1e76fb27ecf42fe7f04487fe2f7e8fab205b9a545ab56a766f6b8b56bb445a73dd6af00ce4d982e82d33f590015b55a6966
6
+ metadata.gz: d7a9a43625d67b0b1b2d070fec123af82fe3a448ca7d5608a3ff44ecf2275ca7467f81a163ffb13eeb57c880c9297ba07c7062dfd8c653f3199414d2858753b5
7
+ data.tar.gz: d66214d414e862f0871003484d949348f26887e8eb0983174ab2ddba7b60c03b10cafbd3ffa9ce9ad9188ce857dd82bc99c929d390e3ad40c1199efc63ae4148
data/lib/lazy/pp/json.rb CHANGED
@@ -14,6 +14,7 @@ module Lazy
14
14
  super(raw)
15
15
  @indent_count = indent_count || 1
16
16
  @newline_separator = false
17
+ @key_max_length = 0
17
18
  @pretty_print = nil
18
19
  end
19
20
 
@@ -30,6 +31,7 @@ module Lazy
30
31
  when Hash
31
32
  @pretty_print.group(indent_width, "{", "}") do
32
33
  first = true
34
+ @key_max_length = object.keys.map(&:length).max
33
35
  object.each do |key, value|
34
36
  @pretty_print.text(",") unless first
35
37
 
@@ -65,7 +67,7 @@ module Lazy
65
67
  end
66
68
  end
67
69
 
68
- def pretty_pring_circle(pretty_print)
70
+ def pretty_print_cycle(pretty_print)
69
71
  pretty_print.text(empty? ? "" : "{...}")
70
72
  end
71
73
 
@@ -108,7 +110,7 @@ module Lazy
108
110
  end
109
111
 
110
112
  def text_key(key)
111
- @pretty_print.pp key
113
+ @pretty_print.text "\"#{key}\"".ljust(@key_max_length + 2)
112
114
  @pretty_print.text ":"
113
115
  end
114
116
 
@@ -3,7 +3,7 @@
3
3
  module Lazy
4
4
  module PP
5
5
  class JSON < String
6
- VERSION = "0.0.1"
6
+ VERSION = "0.0.2"
7
7
  end
8
8
  end
9
9
  end
data/test/test_hash.rb CHANGED
@@ -29,6 +29,15 @@ EXPECTED
29
29
  EXPECTED
30
30
  end
31
31
 
32
+ def test_different_key_length
33
+ assert_lazy_json(<<EXPECTED, '{"key-first":"value1", "key-second":"value2"}')
34
+ {
35
+ "key-first" :"value1",
36
+ "key-second":"value2"
37
+ }
38
+ EXPECTED
39
+ end
40
+
32
41
  def test_short_array_as_value
33
42
  actual_string = <<ACTUAL
34
43
  {"key1":["1","2"], "key2":"value2"}
@@ -58,7 +67,23 @@ ACTUAL
58
67
  EXPECTED
59
68
  end
60
69
 
61
- def test_including_hash
70
+ def test_including_short_hash
71
+ actual_string = <<ACTUAL
72
+ {"key1":{"1":"2","3rd":"4th"}, "key2":"value2"}
73
+ ACTUAL
74
+ assert_lazy_json(<<EXPECTED, actual_string)
75
+ {
76
+ "key1":
77
+ {
78
+ "1" :"2",
79
+ "3rd":"4th"
80
+ },
81
+ "key2":"value2"
82
+ }
83
+ EXPECTED
84
+ end
85
+
86
+ def test_including_long_hash
62
87
  actual_string = <<ACTUAL
63
88
  {"key1":{"key1-1":"value1-1","key1-2":"value1-2"}, "key2":"value2"}
64
89
  ACTUAL
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy-pp-json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshihara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-08 00:00:00.000000000 Z
11
+ date: 2014-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
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
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: test-unit
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: test-unit-notify
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: |-
@@ -112,19 +112,19 @@ executables:
112
112
  extensions: []
113
113
  extra_rdoc_files: []
114
114
  files:
115
- - Gemfile
116
- - LICENSE.txt
117
115
  - README.md
116
+ - LICENSE.txt
118
117
  - Rakefile
119
- - bin/lazy-pp-json
118
+ - Gemfile
120
119
  - lazy-pp-json.gemspec
121
- - lib/lazy-pp-json.rb
122
- - lib/lazy/pp/json.rb
123
120
  - lib/lazy/pp/json/version.rb
121
+ - lib/lazy/pp/json.rb
122
+ - lib/lazy-pp-json.rb
124
123
  - test/run-test.rb
125
124
  - test/test_array.rb
126
125
  - test/test_hash.rb
127
126
  - test/testutils.rb
127
+ - bin/lazy-pp-json
128
128
  homepage: ''
129
129
  licenses:
130
130
  - MIT
@@ -135,17 +135,17 @@ require_paths:
135
135
  - lib
136
136
  required_ruby_version: !ruby/object:Gem::Requirement
137
137
  requirements:
138
- - - ">="
138
+ - - '>='
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
141
  required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - '>='
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  requirements: []
147
147
  rubyforge_project:
148
- rubygems_version: 2.2.0
148
+ rubygems_version: 2.1.11
149
149
  signing_key:
150
150
  specification_version: 4
151
151
  summary: Lazy pp json responses