amazing_print 2.0.0 → 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 +16 -0
- data/README.md +18 -17
- data/lib/amazing_print/colorize.rb +1 -1
- data/lib/amazing_print/custom_defaults.rb +1 -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/base_formatter.rb +2 -1
- data/lib/amazing_print/formatters/hash_formatter.rb +18 -9
- data/lib/amazing_print/formatters/object_formatter.rb +2 -3
- data/lib/amazing_print/formatters/struct_formatter.rb +2 -3
- data/lib/amazing_print/inspector.rb +5 -3
- data/lib/amazing_print/version.rb +1 -1
- metadata +3 -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,22 @@
|
|
|
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
|
+
|
|
5
21
|
## v2.0.0
|
|
6
22
|
|
|
7
23
|
- Rework hash formats and add JSON format (#83)
|
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
|
-
hash_format: :symbol
|
|
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
|
|
@@ -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)}"
|
|
@@ -84,9 +84,9 @@ module AmazingPrint
|
|
|
84
84
|
return key.inspect.size if symbol?(key)
|
|
85
85
|
|
|
86
86
|
if options[:html]
|
|
87
|
-
single_line { inspector.awesome(key) }
|
|
87
|
+
colorless_size(single_line { inspector.awesome(key) })
|
|
88
88
|
else
|
|
89
|
-
|
|
89
|
+
no_colors { single_line { inspector.awesome(key) }.size }
|
|
90
90
|
end
|
|
91
91
|
end
|
|
92
92
|
|
|
@@ -135,22 +135,31 @@ module AmazingPrint
|
|
|
135
135
|
|
|
136
136
|
# Move the colon to the right side of the symbol
|
|
137
137
|
key_string = key.inspect.include?('"') ? key.inspect.sub(':', '') : key.to_s
|
|
138
|
-
awesome_key =
|
|
138
|
+
awesome_key = format_key(key).sub(/#{Regexp.escape(key.inspect)}/, "#{key_string}:")
|
|
139
139
|
|
|
140
140
|
"#{align(awesome_key, width)} #{inspector.awesome(value)}"
|
|
141
141
|
end
|
|
142
142
|
|
|
143
143
|
def pre_ruby19_syntax(key, value, width)
|
|
144
|
-
awesome_key = single_line {
|
|
144
|
+
awesome_key = single_line { format_key(key) }
|
|
145
|
+
|
|
145
146
|
"#{align(awesome_key, width)}#{colorize(' => ', :hash)}#{inspector.awesome(value)}"
|
|
146
147
|
end
|
|
147
148
|
|
|
148
|
-
def
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
|
152
161
|
ensure
|
|
153
|
-
options[:
|
|
162
|
+
options[:colors] = old_colors
|
|
154
163
|
end
|
|
155
164
|
|
|
156
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,13 +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
|
|
63
|
+
# rubocop:disable-next Style/ColonMethodCall
|
|
64
64
|
if defined?(Data) && struct.is_a?(Data)
|
|
65
65
|
Kernel::format("data #{struct.class}:0x%08x", struct.__id__ * 2)
|
|
66
66
|
else
|
|
67
67
|
Kernel::format("#{struct.class.superclass}:#{struct.class}:0x%08x", struct.__id__ * 2)
|
|
68
68
|
end
|
|
69
|
-
# rubocop:enable Style/ColonMethodCall
|
|
70
69
|
end
|
|
71
70
|
|
|
72
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'
|
|
@@ -32,7 +32,7 @@ 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.
|
|
@@ -164,6 +164,8 @@ module AmazingPrint
|
|
|
164
164
|
#---------------------------------------------------------------------------
|
|
165
165
|
def merge_options!(options = {})
|
|
166
166
|
@options[:color].merge!(options.delete(:color) || {})
|
|
167
|
+
@options[:colors] = :none if options[:plain]
|
|
168
|
+
|
|
167
169
|
@options.merge!(options)
|
|
168
170
|
end
|
|
169
171
|
|
|
@@ -204,4 +206,4 @@ module AmazingPrint
|
|
|
204
206
|
end
|
|
205
207
|
end
|
|
206
208
|
|
|
207
|
-
# rubocop:enable Metrics/
|
|
209
|
+
# rubocop:enable Metrics/MethodLength
|
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
|
|
@@ -71,14 +71,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
71
71
|
requirements:
|
|
72
72
|
- - ">="
|
|
73
73
|
- !ruby/object:Gem::Version
|
|
74
|
-
version: 3.
|
|
74
|
+
version: 3.2.0
|
|
75
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
requirements:
|
|
77
77
|
- - ">="
|
|
78
78
|
- !ruby/object:Gem::Version
|
|
79
79
|
version: '0'
|
|
80
80
|
requirements: []
|
|
81
|
-
rubygems_version:
|
|
81
|
+
rubygems_version: 4.0.20
|
|
82
82
|
specification_version: 4
|
|
83
83
|
summary: Pretty print Ruby objects with proper indentation and colors
|
|
84
84
|
test_files: []
|