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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8072cc250156956633f6956bdb3bc23c93b8c1e2c578471bfac37de210b8dc2d
4
- data.tar.gz: 1abd0d9bc13804532c4fd5c4c2c2c180a32980809d3381866b367981d5396c62
3
+ metadata.gz: 6020ecb594da670f3354aaddf2444e65b65d0ebe513d0ca2d42c879afb1921ae
4
+ data.tar.gz: cffea382697c97a5c9984b1fdcb5533ed705539e96fd26d36a5fe9c05e4bce30
5
5
  SHA512:
6
- metadata.gz: 9797830f7ff0055f00ce07a86ecb28ad912e1081c7718d5e0f41bd04167d11c93553182f96b029df10759116e29348434e153419a14c3fd3b11c358b842280c9
7
- data.tar.gz: f9e236e54d4a1d10c2f54f70f71ebbd51fb799485cb9ccb5dd15aa33b5a33d60281f44117b81d414a8b57a69f79d8fb79b54e823684045c543fdab5c9943abe0
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.1
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, # 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
- plain: false, # Use colors.
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.
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 ~/.irbrc file:
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 ~/.pryrc:
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 'ap' method to the Logger and ActiveSupport::BufferedLogger classes
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 'ap' method to the ActionView::Base class making it available
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[:plain] || !options[:color][type] || !inspector.colorize?
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
@@ -66,7 +66,7 @@ module AmazingPrint
66
66
  indent: 2
67
67
  }
68
68
 
69
- opts[:plain] = true if ::DEBUGGER__::CONFIG[:no_color]
69
+ opts[:colors] = :none if ::DEBUGGER__::CONFIG[:no_color]
70
70
 
71
71
  if obj.respond_to?(:ai)
72
72
  obj.ai(opts)
@@ -42,4 +42,6 @@ AmazingPrint::Formatter.include AmazingPrint::ActiveSupport
42
42
  #
43
43
  # Colorize Rails logs.
44
44
  #
45
- AmazingPrint.force_colors! colors: ActiveSupport::LogSubscriber.colorize_logging if defined?(ActiveSupport::LogSubscriber)
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).each_with_object({}) do |c, hash|
33
- hash[c[0].to_sym] = c[1]
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)}"
@@ -144,7 +144,8 @@ module AmazingPrint
144
144
  end
145
145
 
146
146
  def colorless(string)
147
- string.gsub(/\e\[[\d;]+m/, '')
147
+ result = string.gsub(/\e\[[\d;]+m/, '')
148
+ result.gsub(%r{<kbd[^>]*>|</kbd>}, '')
148
149
  end
149
150
 
150
151
  def colorless_size(string)
@@ -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) }.size
87
+ colorless_size(single_line { inspector.awesome(key) })
88
88
  else
89
- plain_single_line { inspector.awesome(key) }.size
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 = inspector.awesome(key).sub(/#{Regexp.escape(key.inspect)}/, "#{key_string}:")
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 { inspector.awesome(key) }
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 plain_single_line(&)
149
- plain = options[:plain]
150
- options[:plain] = true
151
- single_line(&)
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[:plain] = plain
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
- unless options[:plain]
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
- unless options[:plain]
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/ClassLength, Metrics/MethodLength
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
- plain: false, # Use colors.
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/ClassLength, Metrics/MethodLength
209
+ # rubocop:enable Metrics/MethodLength
@@ -7,6 +7,6 @@
7
7
  #------------------------------------------------------------------------------
8
8
  module AmazingPrint
9
9
  def self.version
10
- '2.0.0'
10
+ '3.0.0'
11
11
  end
12
12
  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: 2.0.0
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.1.0
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: 3.6.9
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: []