amazing_print 1.8.1 → 3.0.0
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/CHANGELOG.md +21 -0
- data/README.md +18 -17
- data/lib/amazing_print/colorize.rb +1 -1
- data/lib/amazing_print/custom_defaults.rb +30 -1
- data/lib/amazing_print/ext/active_support.rb +3 -1
- data/lib/amazing_print/ext/nobrainer.rb +0 -4
- data/lib/amazing_print/ext/sequel.rb +2 -2
- data/lib/amazing_print/formatters/array_formatter.rb +7 -2
- data/lib/amazing_print/formatters/base_formatter.rb +2 -1
- data/lib/amazing_print/formatters/hash_formatter.rb +59 -12
- data/lib/amazing_print/formatters/mswin_helper.rb +1 -0
- data/lib/amazing_print/formatters/object_formatter.rb +2 -3
- data/lib/amazing_print/formatters/struct_formatter.rb +7 -4
- data/lib/amazing_print/inspector.rb +13 -6
- data/lib/amazing_print/json_helper.rb +29 -0
- data/lib/amazing_print/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6020ecb594da670f3354aaddf2444e65b65d0ebe513d0ca2d42c879afb1921ae
|
|
4
|
+
data.tar.gz: cffea382697c97a5c9984b1fdcb5533ed705539e96fd26d36a5fe9c05e4bce30
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 051f4d8f6bda59fdcd09f52eea6775cc80ddce2bd130dc86880172e76693980a93b87cff63a73b08e037ded38bb8846746f778bfb589a8d45f8b4795e7245031
|
|
7
|
+
data.tar.gz: 126faa9850f7e963c8b6c0de45a4353cee2715557dbe714189ad718f5ceaaa09212131e943255ce9bba153cb8a25f13c8fdddb90f3498d7698164519a283ab37
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## v3.0.0
|
|
6
|
+
|
|
7
|
+
- Support Rails 8.2 (#144, #158)
|
|
8
|
+
- Change default coloring behavior to only color values, instead of keys and values (#151)
|
|
9
|
+
- Support Ruby 4.0 (#150)
|
|
10
|
+
- Fix alignment when using html: true with colors (#146)
|
|
11
|
+
- Fix forcing colors on future version of Rails (#144)
|
|
12
|
+
- Add `colors` option that can have the following values (#143):
|
|
13
|
+
- `:all`. Colors hash keys and values.
|
|
14
|
+
- `:values_only`. Only colors hash values, not hash keys. Default.
|
|
15
|
+
- `:none`. Disables colors.
|
|
16
|
+
- Deprecate `plain` option in favor of `colors: :none` (#143)
|
|
17
|
+
- Fix alignment when using `html: true` with colors (#146)
|
|
18
|
+
- Add option disable colors for hash keys (#142)
|
|
19
|
+
- Document `rdbg!` feature (#139)
|
|
20
|
+
|
|
21
|
+
## v2.0.0
|
|
22
|
+
|
|
23
|
+
- Rework hash formats and add JSON format (#83)
|
|
24
|
+
- Format Data objects using StructFormatter (#138)
|
|
25
|
+
|
|
5
26
|
## v1.8.1
|
|
6
27
|
|
|
7
28
|
- Fix authors list in gemspec #128
|
data/README.md
CHANGED
|
@@ -14,7 +14,7 @@ AmazingPrint is a fork of [AwesomePrint](https://github.com/awesome-print/awesom
|
|
|
14
14
|
|
|
15
15
|
### Supported Versions ###
|
|
16
16
|
|
|
17
|
-
- Ruby >= 3.
|
|
17
|
+
- Ruby >= 3.2
|
|
18
18
|
- Rails >= 6.1
|
|
19
19
|
|
|
20
20
|
### Installation ###
|
|
@@ -34,18 +34,18 @@ ap object, options = {}
|
|
|
34
34
|
Default options:
|
|
35
35
|
|
|
36
36
|
```ruby
|
|
37
|
-
indent: 4,
|
|
38
|
-
index: true,
|
|
39
|
-
html: false,
|
|
40
|
-
multiline: true,
|
|
41
|
-
|
|
42
|
-
raw: false,
|
|
43
|
-
sort_keys: false,
|
|
44
|
-
sort_vars: true,
|
|
45
|
-
limit: false,
|
|
46
|
-
|
|
47
|
-
class_name: :class,
|
|
48
|
-
object_id: true,
|
|
37
|
+
indent: 4, # Number of spaces for indenting.
|
|
38
|
+
index: true, # Display array indices.
|
|
39
|
+
html: false, # Use ANSI color codes rather than HTML.
|
|
40
|
+
multiline: true, # Display in multiple lines.
|
|
41
|
+
colors: :values_only, # Controls what should be colored. Can be one of :all, :values_only, or :none
|
|
42
|
+
raw: false, # Do not recursively format instance variables.
|
|
43
|
+
sort_keys: false, # Do not sort hash keys.
|
|
44
|
+
sort_vars: true, # Sort instance variables.
|
|
45
|
+
limit: false, # Limit arrays & hashes. Accepts bool or int.
|
|
46
|
+
hash_format: :symbol, # The format for printing hashes. Can be one of :json, :rocket, or :symbol
|
|
47
|
+
class_name: :class, # Method called to report the instance class name. (e.g. :to_s)
|
|
48
|
+
object_id: true, # Show object id.
|
|
49
49
|
color: {
|
|
50
50
|
args: :whiteish,
|
|
51
51
|
array: :white,
|
|
@@ -267,16 +267,17 @@ rails>
|
|
|
267
267
|
|
|
268
268
|
### IRB integration ###
|
|
269
269
|
To use amazing_print as the default formatter in irb and the Rails console, add the following
|
|
270
|
-
code to your
|
|
270
|
+
code to your `~/.irbrc` file:
|
|
271
271
|
|
|
272
272
|
```ruby
|
|
273
273
|
require "amazing_print"
|
|
274
274
|
AmazingPrint.irb!
|
|
275
|
+
AmazingPrint.rdbg! # Enables integration with ruby debug
|
|
275
276
|
```
|
|
276
277
|
|
|
277
278
|
### PRY integration ###
|
|
278
279
|
If you miss amazing_print's way of formatting output, here's how you can use it in place
|
|
279
|
-
of the formatting which comes with pry. Add the following code to your
|
|
280
|
+
of the formatting which comes with pry. Add the following code to your `~/.pryrc`:
|
|
280
281
|
|
|
281
282
|
```ruby
|
|
282
283
|
require "amazing_print"
|
|
@@ -284,7 +285,7 @@ AmazingPrint.pry!
|
|
|
284
285
|
```
|
|
285
286
|
|
|
286
287
|
### Logger Convenience Method ###
|
|
287
|
-
amazing_print adds the
|
|
288
|
+
amazing_print adds the `ap` method to the `Logger` and `ActiveSupport::BufferedLogger` classes
|
|
288
289
|
letting you call:
|
|
289
290
|
|
|
290
291
|
logger.ap object
|
|
@@ -304,7 +305,7 @@ You can also pass additional options (providing `nil` or leaving off `level` wil
|
|
|
304
305
|
logger.ap object, { level: :info, sort_keys: true }
|
|
305
306
|
|
|
306
307
|
### ActionView Convenience Method ###
|
|
307
|
-
amazing_print adds the
|
|
308
|
+
amazing_print adds the `ap` method to the `ActionView::Base` class making it available
|
|
308
309
|
within Rails templates. For example:
|
|
309
310
|
|
|
310
311
|
<%= ap @accounts.first %> # ERB
|
|
@@ -10,7 +10,7 @@ module AmazingPrint
|
|
|
10
10
|
#------------------------------------------------------------------------------
|
|
11
11
|
def colorize(str, type)
|
|
12
12
|
str = CGI.escapeHTML(str) if options[:html]
|
|
13
|
-
return str if options[:
|
|
13
|
+
return str if options[:colors] == :none || !options[:color][type] || !inspector.colorize?
|
|
14
14
|
|
|
15
15
|
AmazingPrint::Colors.public_send(options[:color][type], str, options[:html])
|
|
16
16
|
end
|
|
@@ -53,6 +53,35 @@ module AmazingPrint
|
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
+
def rdbg!
|
|
57
|
+
return unless defined?(::DEBUGGER__::SESSION)
|
|
58
|
+
|
|
59
|
+
::DEBUGGER__::SESSION.extend_feature(
|
|
60
|
+
thread_client: Module.new do
|
|
61
|
+
# rdbg calls this for both p and pp printing paths
|
|
62
|
+
def color_pp(obj, width)
|
|
63
|
+
opts = {
|
|
64
|
+
multiline: true,
|
|
65
|
+
index: false,
|
|
66
|
+
indent: 2
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
opts[:colors] = :none if ::DEBUGGER__::CONFIG[:no_color]
|
|
70
|
+
|
|
71
|
+
if obj.respond_to?(:ai)
|
|
72
|
+
obj.ai(opts)
|
|
73
|
+
else
|
|
74
|
+
# Fallback if AP isn't mixed into the object for some reason
|
|
75
|
+
super
|
|
76
|
+
end
|
|
77
|
+
rescue StandardError
|
|
78
|
+
# Never break the debugger; fall back to rdbg default
|
|
79
|
+
super
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
)
|
|
83
|
+
end
|
|
84
|
+
|
|
56
85
|
##
|
|
57
86
|
# Reload the cached custom configurations.
|
|
58
87
|
#
|
|
@@ -65,7 +94,7 @@ module AmazingPrint
|
|
|
65
94
|
# Takes a value and returns true unless it is false or nil
|
|
66
95
|
# This is an alternative to the less readable !!(value)
|
|
67
96
|
# https://github.com/bbatsov/ruby-style-guide#no-bang-bang
|
|
68
|
-
def boolean(value)
|
|
97
|
+
def boolean(value) # rubocop:todo Naming/PredicateMethod
|
|
69
98
|
value ? true : false
|
|
70
99
|
end
|
|
71
100
|
end
|
|
@@ -42,4 +42,6 @@ AmazingPrint::Formatter.include AmazingPrint::ActiveSupport
|
|
|
42
42
|
#
|
|
43
43
|
# Colorize Rails logs.
|
|
44
44
|
#
|
|
45
|
-
AmazingPrint.force_colors!
|
|
45
|
+
AmazingPrint.force_colors!(
|
|
46
|
+
colors: ActiveSupport.try(:colorize_logging) || ActiveSupport::LogSubscriber.try(:colorize_logging)
|
|
47
|
+
)
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# rubocop:disable Style/HashTransformValues
|
|
4
|
-
|
|
5
3
|
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
|
6
4
|
#
|
|
7
5
|
# AmazingPrint is freely distributable under the terms of MIT license.
|
|
@@ -53,5 +51,3 @@ module AmazingPrint
|
|
|
53
51
|
end
|
|
54
52
|
|
|
55
53
|
AmazingPrint::Formatter.include AmazingPrint::NoBrainer
|
|
56
|
-
|
|
57
|
-
# rubocop:enable Style/HashTransformValues
|
|
@@ -29,8 +29,8 @@ module AmazingPrint
|
|
|
29
29
|
# Format Sequel Document object.
|
|
30
30
|
#------------------------------------------------------------------------------
|
|
31
31
|
def awesome_sequel_document(object)
|
|
32
|
-
data = object.values.sort_by(&:to_s).
|
|
33
|
-
|
|
32
|
+
data = object.values.sort_by(&:to_s).to_h do |c|
|
|
33
|
+
[c[0].to_sym, c[1]]
|
|
34
34
|
end
|
|
35
35
|
data = { errors: object.errors, values: data } unless object.errors.empty?
|
|
36
36
|
"#{object} #{awesome_hash(data)}"
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative 'base_formatter'
|
|
4
|
+
require_relative '../json_helper'
|
|
4
5
|
|
|
5
6
|
module AmazingPrint
|
|
6
7
|
module Formatters
|
|
7
8
|
class ArrayFormatter < BaseFormatter
|
|
9
|
+
include AmazingPrint::JSONHelper
|
|
10
|
+
|
|
8
11
|
attr_reader :array, :inspector, :options
|
|
9
12
|
|
|
10
13
|
def initialize(array, inspector)
|
|
@@ -51,7 +54,9 @@ module AmazingPrint
|
|
|
51
54
|
def generate_printable_array
|
|
52
55
|
array.map.with_index do |item, index|
|
|
53
56
|
array_prefix(index, width(array)).tap do |temp|
|
|
54
|
-
indented
|
|
57
|
+
indented do
|
|
58
|
+
temp << json_awesome(item)
|
|
59
|
+
end
|
|
55
60
|
end
|
|
56
61
|
end
|
|
57
62
|
end
|
|
@@ -127,7 +132,7 @@ module AmazingPrint
|
|
|
127
132
|
end
|
|
128
133
|
|
|
129
134
|
def generic_prefix(iteration, width, padding = '')
|
|
130
|
-
if options[:index]
|
|
135
|
+
if options[:index] && options[:hash_format] != :json
|
|
131
136
|
indent + colorize("[#{iteration.to_s.rjust(width)}] ", :array)
|
|
132
137
|
else
|
|
133
138
|
indent + padding
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative 'base_formatter'
|
|
4
|
+
require_relative '../json_helper'
|
|
4
5
|
|
|
5
6
|
module AmazingPrint
|
|
6
7
|
module Formatters
|
|
7
8
|
class HashFormatter < BaseFormatter
|
|
9
|
+
include AmazingPrint::JSONHelper
|
|
10
|
+
|
|
11
|
+
VALID_HASH_FORMATS = %i[json rocket symbol].freeze
|
|
12
|
+
|
|
13
|
+
class InvalidHashFormatError < StandardError; end
|
|
14
|
+
|
|
8
15
|
attr_reader :hash, :inspector, :options
|
|
9
16
|
|
|
10
17
|
def initialize(hash, inspector)
|
|
@@ -12,6 +19,11 @@ module AmazingPrint
|
|
|
12
19
|
@hash = hash
|
|
13
20
|
@inspector = inspector
|
|
14
21
|
@options = inspector.options
|
|
22
|
+
|
|
23
|
+
return if VALID_HASH_FORMATS.include?(options[:hash_format])
|
|
24
|
+
|
|
25
|
+
raise(InvalidHashFormatError, "Invalid hash_format: #{options[:hash_format].inspect}. " \
|
|
26
|
+
"Must be one of #{VALID_HASH_FORMATS}")
|
|
15
27
|
end
|
|
16
28
|
|
|
17
29
|
def format
|
|
@@ -48,10 +60,13 @@ module AmazingPrint
|
|
|
48
60
|
|
|
49
61
|
data.map! do |key, value|
|
|
50
62
|
indented do
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
63
|
+
case options[:hash_format]
|
|
64
|
+
when :json
|
|
65
|
+
json_syntax(key, value, width)
|
|
66
|
+
when :rocket
|
|
54
67
|
pre_ruby19_syntax(key, value, width)
|
|
68
|
+
when :symbol
|
|
69
|
+
ruby19_syntax(key, value, width)
|
|
55
70
|
end
|
|
56
71
|
end
|
|
57
72
|
end
|
|
@@ -69,9 +84,9 @@ module AmazingPrint
|
|
|
69
84
|
return key.inspect.size if symbol?(key)
|
|
70
85
|
|
|
71
86
|
if options[:html]
|
|
72
|
-
single_line { inspector.awesome(key) }
|
|
87
|
+
colorless_size(single_line { inspector.awesome(key) })
|
|
73
88
|
else
|
|
74
|
-
|
|
89
|
+
no_colors { single_line { inspector.awesome(key) }.size }
|
|
75
90
|
end
|
|
76
91
|
end
|
|
77
92
|
|
|
@@ -91,28 +106,60 @@ module AmazingPrint
|
|
|
91
106
|
end
|
|
92
107
|
end
|
|
93
108
|
|
|
109
|
+
def string?(key)
|
|
110
|
+
key[0] == '"' && key[-1] == '"'
|
|
111
|
+
end
|
|
112
|
+
|
|
94
113
|
def symbol?(key)
|
|
95
114
|
key.is_a?(Symbol)
|
|
96
115
|
end
|
|
97
116
|
|
|
117
|
+
def json_format?
|
|
118
|
+
options[:hash_format] == :json
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def json_syntax(key, value, width)
|
|
122
|
+
unless defined?(JSON)
|
|
123
|
+
warn 'JSON is not defined. Defaulting hash format to symbol'
|
|
124
|
+
return ruby19_syntax(key, value, width)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
formatted_key = json_awesome(key, is_key: true)
|
|
128
|
+
formatted_value = json_awesome(value)
|
|
129
|
+
|
|
130
|
+
"#{align(formatted_key, width)}#{colorize(': ', :hash)}#{formatted_value}"
|
|
131
|
+
end
|
|
132
|
+
|
|
98
133
|
def ruby19_syntax(key, value, width)
|
|
134
|
+
return pre_ruby19_syntax(key, value, width) unless symbol?(key)
|
|
135
|
+
|
|
99
136
|
# Move the colon to the right side of the symbol
|
|
100
|
-
|
|
137
|
+
key_string = key.inspect.include?('"') ? key.inspect.sub(':', '') : key.to_s
|
|
138
|
+
awesome_key = format_key(key).sub(/#{Regexp.escape(key.inspect)}/, "#{key_string}:")
|
|
101
139
|
|
|
102
140
|
"#{align(awesome_key, width)} #{inspector.awesome(value)}"
|
|
103
141
|
end
|
|
104
142
|
|
|
105
143
|
def pre_ruby19_syntax(key, value, width)
|
|
106
|
-
awesome_key = single_line {
|
|
144
|
+
awesome_key = single_line { format_key(key) }
|
|
145
|
+
|
|
107
146
|
"#{align(awesome_key, width)}#{colorize(' => ', :hash)}#{inspector.awesome(value)}"
|
|
108
147
|
end
|
|
109
148
|
|
|
110
|
-
def
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
149
|
+
def format_key(key)
|
|
150
|
+
if options[:colors] == :values_only
|
|
151
|
+
no_colors { inspector.awesome(key) }
|
|
152
|
+
else
|
|
153
|
+
inspector.awesome(key)
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def no_colors
|
|
158
|
+
old_colors = options[:colors]
|
|
159
|
+
options[:colors] = :none
|
|
160
|
+
yield
|
|
114
161
|
ensure
|
|
115
|
-
options[:
|
|
162
|
+
options[:colors] = old_colors
|
|
116
163
|
end
|
|
117
164
|
|
|
118
165
|
def single_line
|
|
@@ -35,7 +35,7 @@ module AmazingPrint
|
|
|
35
35
|
align(declaration, declaration.size)
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
if options[:colors] != :none
|
|
39
39
|
key = if key =~ /(@\w+)/
|
|
40
40
|
key.sub(Regexp.last_match(1), colorize(Regexp.last_match(1), :variable))
|
|
41
41
|
else
|
|
@@ -67,9 +67,8 @@ module AmazingPrint
|
|
|
67
67
|
|
|
68
68
|
# We need to ensure that the original Kernel#format is used here instead of the one
|
|
69
69
|
# defined above.
|
|
70
|
-
# rubocop:disable Style/ColonMethodCall
|
|
70
|
+
# rubocop:disable-next Style/ColonMethodCall
|
|
71
71
|
str + Kernel::format(':0x%08x', object.__id__ * 2)
|
|
72
|
-
# rubocop:enable Style/ColonMethodCall
|
|
73
72
|
end
|
|
74
73
|
|
|
75
74
|
def left_aligned
|
|
@@ -35,7 +35,7 @@ module AmazingPrint
|
|
|
35
35
|
align(declaration, declaration.size)
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
if options[:colors] != :none
|
|
39
39
|
key = if key =~ /(@\w+)/
|
|
40
40
|
key.sub(Regexp.last_match(1), colorize(Regexp.last_match(1), :variable))
|
|
41
41
|
else
|
|
@@ -60,9 +60,12 @@ module AmazingPrint
|
|
|
60
60
|
def awesome_instance
|
|
61
61
|
# We need to ensure that the original Kernel#format is used here instead of the one defined
|
|
62
62
|
# above.
|
|
63
|
-
# rubocop:disable Style/ColonMethodCall
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
# rubocop:disable-next Style/ColonMethodCall
|
|
64
|
+
if defined?(Data) && struct.is_a?(Data)
|
|
65
|
+
Kernel::format("data #{struct.class}:0x%08x", struct.__id__ * 2)
|
|
66
|
+
else
|
|
67
|
+
Kernel::format("#{struct.class.superclass}:#{struct.class}:0x%08x", struct.__id__ * 2)
|
|
68
|
+
end
|
|
66
69
|
end
|
|
67
70
|
|
|
68
71
|
def left_aligned
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
|
7
7
|
#------------------------------------------------------------------------------
|
|
8
8
|
|
|
9
|
-
# rubocop:disable Metrics/
|
|
9
|
+
# rubocop:disable Metrics/MethodLength
|
|
10
10
|
|
|
11
11
|
require_relative 'indentator'
|
|
12
12
|
require_relative 'ext_loader'
|
|
@@ -20,7 +20,7 @@ module AmazingPrint
|
|
|
20
20
|
##
|
|
21
21
|
# Unload the cached dotfile and load it again.
|
|
22
22
|
#
|
|
23
|
-
def self.reload_dotfile
|
|
23
|
+
def self.reload_dotfile # rubocop:todo Naming/PredicateMethod
|
|
24
24
|
@@dotfile = nil
|
|
25
25
|
new.send :load_dotfile
|
|
26
26
|
true
|
|
@@ -32,12 +32,12 @@ module AmazingPrint
|
|
|
32
32
|
index: true, # Display array indices.
|
|
33
33
|
html: false, # Use ANSI color codes rather than HTML.
|
|
34
34
|
multiline: true, # Display in multiple lines.
|
|
35
|
-
|
|
35
|
+
colors: :values_only, # Controls what should be colored. Can be one of :all, :values_only, or :none
|
|
36
36
|
raw: false, # Do not recursively format instance variables.
|
|
37
37
|
sort_keys: false, # Do not sort hash keys.
|
|
38
38
|
sort_vars: true, # Sort instance variables.
|
|
39
39
|
limit: false, # Limit arrays & hashes. Accepts bool or int.
|
|
40
|
-
|
|
40
|
+
hash_format: :symbol, # The format for printing hashes. Can be one of :json, :rocket, or :symbol
|
|
41
41
|
class_name: :class, # Method used to get Instance class name.
|
|
42
42
|
object_id: true, # Show object_id.
|
|
43
43
|
color: {
|
|
@@ -150,7 +150,12 @@ module AmazingPrint
|
|
|
150
150
|
when File then :file
|
|
151
151
|
when Dir then :dir
|
|
152
152
|
when Struct then :struct
|
|
153
|
-
else
|
|
153
|
+
else
|
|
154
|
+
if defined?(Data) && object.is_a?(Data)
|
|
155
|
+
:struct
|
|
156
|
+
else
|
|
157
|
+
object.class.to_s.gsub(/:+/, '_').downcase.to_sym
|
|
158
|
+
end
|
|
154
159
|
end
|
|
155
160
|
end
|
|
156
161
|
|
|
@@ -159,6 +164,8 @@ module AmazingPrint
|
|
|
159
164
|
#---------------------------------------------------------------------------
|
|
160
165
|
def merge_options!(options = {})
|
|
161
166
|
@options[:color].merge!(options.delete(:color) || {})
|
|
167
|
+
@options[:colors] = :none if options[:plain]
|
|
168
|
+
|
|
162
169
|
@options.merge!(options)
|
|
163
170
|
end
|
|
164
171
|
|
|
@@ -199,4 +206,4 @@ module AmazingPrint
|
|
|
199
206
|
end
|
|
200
207
|
end
|
|
201
208
|
|
|
202
|
-
# rubocop:enable Metrics/
|
|
209
|
+
# rubocop:enable Metrics/MethodLength
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
# Helper module for hash_format: :json
|
|
5
|
+
#
|
|
6
|
+
module AmazingPrint
|
|
7
|
+
module JSONHelper
|
|
8
|
+
VALUE_CLASSES_NOT_TO_CONVERT = %w[Array BigDecimal Float Hash Integer String].freeze
|
|
9
|
+
|
|
10
|
+
def json_awesome(object, is_key: false)
|
|
11
|
+
return inspector.awesome(object) unless options[:hash_format] == :json && object.respond_to?(:to_json)
|
|
12
|
+
|
|
13
|
+
if object.nil?
|
|
14
|
+
# Color null like we do nil
|
|
15
|
+
colorize(object.to_json, :nilclass)
|
|
16
|
+
elsif is_key && object.is_a?(Numeric)
|
|
17
|
+
# JSON keys should be a string
|
|
18
|
+
inspector.awesome(object.to_s)
|
|
19
|
+
elsif VALUE_CLASSES_NOT_TO_CONVERT.include?(object.class.name) || !object.respond_to?(:to_json)
|
|
20
|
+
# These objects should not be converted to strings with #to_json so we can treat them normally
|
|
21
|
+
inspector.awesome(object)
|
|
22
|
+
else
|
|
23
|
+
# Remove surrounding quotes added by #to_json from the standard library since
|
|
24
|
+
# inspector.awesome is going to add those for us for strings.
|
|
25
|
+
inspector.awesome(object.to_json.gsub(/\A"/, '').gsub(/"\z/, ''))
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: amazing_print
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Dvorkin
|
|
@@ -56,6 +56,7 @@ files:
|
|
|
56
56
|
- lib/amazing_print/formatters/struct_formatter.rb
|
|
57
57
|
- lib/amazing_print/indentator.rb
|
|
58
58
|
- lib/amazing_print/inspector.rb
|
|
59
|
+
- lib/amazing_print/json_helper.rb
|
|
59
60
|
- lib/amazing_print/version.rb
|
|
60
61
|
- lib/ap.rb
|
|
61
62
|
homepage: https://github.com/amazing-print/amazing_print
|
|
@@ -70,14 +71,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
70
71
|
requirements:
|
|
71
72
|
- - ">="
|
|
72
73
|
- !ruby/object:Gem::Version
|
|
73
|
-
version: 3.
|
|
74
|
+
version: 3.2.0
|
|
74
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
76
|
requirements:
|
|
76
77
|
- - ">="
|
|
77
78
|
- !ruby/object:Gem::Version
|
|
78
79
|
version: '0'
|
|
79
80
|
requirements: []
|
|
80
|
-
rubygems_version:
|
|
81
|
+
rubygems_version: 4.0.20
|
|
81
82
|
specification_version: 4
|
|
82
83
|
summary: Pretty print Ruby objects with proper indentation and colors
|
|
83
84
|
test_files: []
|