amazing_print 1.2.1 → 1.2.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
  SHA256:
3
- metadata.gz: 5d1a2c6f2a9c7b910cf3a164259418a8b89e37ac5584ff9a99f5d2ab6079ca70
4
- data.tar.gz: 89963f9ddcfc830c4901963a2c0dc314bb0cda65c18dd601cc13b6bee146cf72
3
+ metadata.gz: 1d16f5d91a4e2a69b255fed58405879e2adfbc390f1c55617e717a06249ec035
4
+ data.tar.gz: 1ddabc2b038aea1b78c956c0d3eb08c4e56294b968da9214235f2db944e579a9
5
5
  SHA512:
6
- metadata.gz: 15bb7524e156bdc2994fe91542c4d5217d50434f9bed4dcd226a577eb17cb0c514b6077072433ae627c60de9e082b90bb1ac1d8c2de6d1fbbe796fd09ed78639
7
- data.tar.gz: 8d598afc6f5b52480df736911725af1112b106ca691e620f0400748b75db1fb31561958749bb9255ffe8ad223fd2442d4ff25570a263a771102debe12c39b81f
6
+ metadata.gz: 0d6edeeb83162ab87b4c3a40cffd126fda850abfbd22531bb2149ae51a89aaac3314cb8a5d7a9a06ce0bf48e4fc9fdc2df29359d6828b11a67b4562a71d12558
7
+ data.tar.gz: d264dd5aba47cf7f9c3681f20979441d7337f8115443bf3052bbf3623914036a6ed96b9e75efae6979f2a74f02bde5d41b7d44b90b06c4ad47e01069bd096f6d
@@ -1,5 +1,12 @@
1
- ## unreleased
2
- - Correctly print active_model_errors for models that don't have tables
1
+ ## v1.2.2
2
+ - Support Ruby 3.0 / IRB 1.2.6 - #57
3
+ - Fix FrozenError - #51
4
+ - Drop support for Ruby 2.3 and 2.4 as well as JRuby 9.1 - #46
5
+ - Add passing of `options` to `Logger#ap` - #55
6
+
7
+ ## v1.2.1
8
+ - Correctly print active_model_errors for models that don't have tables - #42 by sahglie
9
+ - Update AmazingPrint::MongoMapper for frozen strings - #44
3
10
 
4
11
  ## v1.2.0
5
12
 
data/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  |
10
10
  [![Gitter](https://badges.gitter.im/amazing-print/community.svg)](https://gitter.im/amazing-print/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
11
11
 
12
- AmazingPrint is a fork of [AwesomePrint](https://github.com/awesome-print/awesome_print) which became stale and should be used in it's place to avoid conflicts. It is a Ruby library that pretty prints Ruby objects in full color exposing their internal structure with proper indentation. Rails ActiveRecord objects and usage within Rails templates are supported via included mixins.
12
+ AmazingPrint is a fork of [AwesomePrint](https://github.com/awesome-print/awesome_print) which became stale and should be used in its place to avoid conflicts. It is a Ruby library that pretty prints Ruby objects in full color exposing their internal structure with proper indentation. Rails ActiveRecord objects and usage within Rails templates are supported via included mixins.
13
13
 
14
14
  ![GitHub API demo](github-api-demo.gif)
15
15
 
@@ -297,6 +297,12 @@ By default, this logs at the :debug level. You can override that globally with:
297
297
  in the custom defaults (see below). You can also override on a per call basis with:
298
298
 
299
299
  logger.ap object, :warn
300
+ # or
301
+ logger.ap object, level: :warn
302
+
303
+ You can also pass additional options (providing `nil` or leaving off `level` will log at the default level):
304
+
305
+ logger.ap object, { level: :info, sort_keys: true }
300
306
 
301
307
  ### ActionView Convenience Method ###
302
308
  amazing_print adds the 'ap' method to the ActionView::Base class making it available
@@ -9,10 +9,17 @@ module AmazingPrint
9
9
  module Logger
10
10
  # Add ap method to logger
11
11
  #------------------------------------------------------------------------------
12
- def ap(object, level = nil)
12
+ def ap(object, options = {})
13
+ if options.is_a?(Hash)
14
+ level = options.delete(:level)
15
+ else
16
+ level = options
17
+ options = {}
18
+ end
19
+
13
20
  level ||= AmazingPrint.defaults[:log_level] if AmazingPrint.defaults
14
21
  level ||= :debug
15
- send level, object.ai
22
+ send level, object.ai(options)
16
23
  end
17
24
  end
18
25
  end
@@ -29,7 +29,7 @@ module AmazingPrint
29
29
 
30
30
  def usual_rb
31
31
  IRB::Irb.class_eval do
32
- def output_value
32
+ def output_value(_omit = false)
33
33
  ap @context.last_value
34
34
  rescue NoMethodError
35
35
  puts "(Object doesn't support #ai)"
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Style/HashTransformValues
4
+
3
5
  # Copyright (c) 2010-2016 Michael Dvorkin and contributors
4
6
  #
5
7
  # AmazingPrint is freely distributable under the terms of MIT license.
@@ -53,3 +55,5 @@ module AmazingPrint
53
55
  end
54
56
 
55
57
  AmazingPrint::Formatter.include AmazingPrint::NoBrainer
58
+
59
+ # rubocop:enable Style/HashTransformValues
@@ -86,11 +86,11 @@ module AmazingPrint
86
86
 
87
87
  def ruby19_syntax(key, value, width)
88
88
  key[0] = ''
89
- align(key, width - 1) << colorize(': ', :hash) << inspector.awesome(value)
89
+ "#{align(key, width - 1)}#{colorize(': ', :hash)}#{inspector.awesome(value)}"
90
90
  end
91
91
 
92
92
  def pre_ruby19_syntax(key, value, width)
93
- align(key, width) + colorize(' => ', :hash) + inspector.awesome(value)
93
+ "#{align(key, width)}#{colorize(' => ', :hash)}#{inspector.awesome(value)}"
94
94
  end
95
95
 
96
96
  def plain_single_line
@@ -7,6 +7,6 @@
7
7
  #------------------------------------------------------------------------------
8
8
  module AmazingPrint
9
9
  def self.version
10
- '1.2.1'
10
+ '1.2.2'
11
11
  end
12
12
  end
@@ -40,34 +40,28 @@ RSpec.describe 'AmazingPrint' do
40
40
  end
41
41
 
42
42
  it "colorizes processes with ENV['ANSICON'] by default" do
43
- begin
44
- stub_tty!
45
- term = ENV['ANSICON']
46
- ENV['ANSICON'] = '1'
47
- expect(@arr.ai(multiline: false)).to eq(COLORIZED)
48
- ensure
49
- ENV['ANSICON'] = term
50
- end
43
+ stub_tty!
44
+ term = ENV['ANSICON']
45
+ ENV['ANSICON'] = '1'
46
+ expect(@arr.ai(multiline: false)).to eq(COLORIZED)
47
+ ensure
48
+ ENV['ANSICON'] = term
51
49
  end
52
50
 
53
51
  it 'does not colorize tty processes running in dumb terminals by default' do
54
- begin
55
- stub_tty!
56
- term = ENV['TERM']
57
- ENV['TERM'] = 'dumb'
58
- expect(@arr.ai(multiline: false)).to eq(PLAIN)
59
- ensure
60
- ENV['TERM'] = term
61
- end
52
+ stub_tty!
53
+ term = ENV['TERM']
54
+ ENV['TERM'] = 'dumb'
55
+ expect(@arr.ai(multiline: false)).to eq(PLAIN)
56
+ ensure
57
+ ENV['TERM'] = term
62
58
  end
63
59
 
64
60
  it 'does not colorize subprocesses by default' do
65
- begin
66
- stub_tty! false
67
- expect(@arr.ai(multiline: false)).to eq(PLAIN)
68
- ensure
69
- stub_tty!
70
- end
61
+ stub_tty! false
62
+ expect(@arr.ai(multiline: false)).to eq(PLAIN)
63
+ ensure
64
+ stub_tty!
71
65
  end
72
66
  end
73
67
 
@@ -82,34 +76,28 @@ RSpec.describe 'AmazingPrint' do
82
76
  end
83
77
 
84
78
  it "colorizes processes with ENV['ANSICON'] set to 0" do
85
- begin
86
- stub_tty!
87
- term = ENV['ANSICON']
88
- ENV['ANSICON'] = '1'
89
- expect(@arr.ai(multiline: false)).to eq(COLORIZED)
90
- ensure
91
- ENV['ANSICON'] = term
92
- end
79
+ stub_tty!
80
+ term = ENV['ANSICON']
81
+ ENV['ANSICON'] = '1'
82
+ expect(@arr.ai(multiline: false)).to eq(COLORIZED)
83
+ ensure
84
+ ENV['ANSICON'] = term
93
85
  end
94
86
 
95
87
  it 'colorizes dumb terminals' do
96
- begin
97
- stub_tty!
98
- term = ENV['TERM']
99
- ENV['TERM'] = 'dumb'
100
- expect(@arr.ai(multiline: false)).to eq(COLORIZED)
101
- ensure
102
- ENV['TERM'] = term
103
- end
88
+ stub_tty!
89
+ term = ENV['TERM']
90
+ ENV['TERM'] = 'dumb'
91
+ expect(@arr.ai(multiline: false)).to eq(COLORIZED)
92
+ ensure
93
+ ENV['TERM'] = term
104
94
  end
105
95
 
106
96
  it 'colorizes subprocess' do
107
- begin
108
- stub_tty! false
109
- expect(@arr.ai(multiline: false)).to eq(COLORIZED)
110
- ensure
111
- stub_tty!
112
- end
97
+ stub_tty! false
98
+ expect(@arr.ai(multiline: false)).to eq(COLORIZED)
99
+ ensure
100
+ stub_tty!
113
101
  end
114
102
  end
115
103
 
@@ -6,19 +6,24 @@ require 'logger'
6
6
  require 'amazing_print/core_ext/logger'
7
7
 
8
8
  RSpec.describe 'AmazingPrint logging extensions' do
9
- before(:all) do
10
- @logger = begin
11
- Logger.new('/dev/null')
12
- rescue Errno::ENOENT
13
- Logger.new('nul')
14
- end
9
+ let(:object) { double }
10
+ let(:options) { { sort_keys: true } }
11
+
12
+ subject(:logger) do
13
+ Logger.new('/dev/null')
14
+ rescue Errno::ENOENT
15
+ Logger.new('nul')
15
16
  end
16
17
 
17
18
  describe 'ap method' do
18
19
  it 'should awesome_inspect the given object' do
19
- object = double
20
20
  expect(object).to receive(:ai)
21
- @logger.ap object
21
+ logger.ap object
22
+ end
23
+
24
+ it 'passes options to `ai`' do
25
+ expect(object).to receive(:ai).with(options)
26
+ logger.ap object, options
22
27
  end
23
28
 
24
29
  describe 'the log level' do
@@ -27,19 +32,38 @@ RSpec.describe 'AmazingPrint logging extensions' do
27
32
  end
28
33
 
29
34
  it 'should fallback to the default :debug log level' do
30
- expect(@logger).to receive(:debug)
31
- @logger.ap(nil)
35
+ expect(logger).to receive(:debug)
36
+ logger.ap nil
32
37
  end
33
38
 
34
39
  it 'should use the global user default if no level passed' do
35
40
  AmazingPrint.defaults = { log_level: :info }
36
- expect(@logger).to receive(:info)
37
- @logger.ap(nil)
41
+ expect(logger).to receive(:info)
42
+ logger.ap nil
38
43
  end
39
44
 
40
45
  it 'should use the passed in level' do
41
- expect(@logger).to receive(:warn)
42
- @logger.ap(nil, :warn)
46
+ expect(logger).to receive(:warn)
47
+ logger.ap nil, :warn
48
+ end
49
+
50
+ it 'makes no difference if passed as a hash or a part of options' do
51
+ expect(logger).to receive(:warn)
52
+ logger.ap nil, { level: :warn }
53
+ end
54
+
55
+ context 'when given options' do
56
+ it 'uses the default log level with the options' do
57
+ expect(logger).to receive(:debug)
58
+ expect(object).to receive(:ai).with(options)
59
+ logger.ap object, options
60
+ end
61
+
62
+ it 'still uses the passed in level with options' do
63
+ expect(logger).to receive(:warn)
64
+ expect(object).to receive(:ai).with(options)
65
+ logger.ap object, options.merge({ level: :warn })
66
+ end
43
67
  end
44
68
  end
45
69
  end
@@ -3,10 +3,8 @@
3
3
  module ExtVerifier
4
4
  def require_dependencies!(dependencies)
5
5
  dependencies.each do |dependency|
6
- begin
7
- require dependency
8
- rescue LoadError
9
- end
6
+ require dependency
7
+ rescue LoadError
10
8
  end
11
9
  end
12
10
  module_function :require_dependencies!
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: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Dvorkin
@@ -9,50 +9,50 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-06-15 00:00:00.000000000 Z
12
+ date: 2020-10-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: appraisal
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '0'
20
+ version: '2.3'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">="
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '0'
27
+ version: '2.3'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: fakefs
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ">="
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: 0.2.1
34
+ version: '1.2'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ">="
39
+ - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: 0.2.1
41
+ version: '1.2'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: nokogiri
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: 1.6.5
48
+ version: '1.10'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: 1.6.5
55
+ version: '1.10'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: pry
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -71,16 +71,16 @@ dependencies:
71
71
  name: rspec
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ">="
74
+ - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: 3.0.0
76
+ version: '3.9'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ">="
81
+ - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: 3.0.0
83
+ version: '3.9'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: rubocop
86
86
  requirement: !ruby/object:Gem::Requirement
@@ -204,7 +204,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
204
204
  requirements:
205
205
  - - ">="
206
206
  - !ruby/object:Gem::Version
207
- version: 2.3.0
207
+ version: 2.5.0
208
208
  required_rubygems_version: !ruby/object:Gem::Requirement
209
209
  requirements:
210
210
  - - ">="
@@ -216,49 +216,49 @@ signing_key:
216
216
  specification_version: 4
217
217
  summary: Pretty print Ruby objects with proper indentation and colors
218
218
  test_files:
219
- - spec/methods_spec.rb
220
- - spec/spec_helper.rb
219
+ - spec/support/active_record_data.rb
220
+ - spec/support/rails_versions.rb
221
+ - spec/support/mongoid_versions.rb
222
+ - spec/support/active_record_data/4_0_multi.txt
223
+ - spec/support/active_record_data/3_2_multi_legacy.txt
224
+ - spec/support/active_record_data/4_1_diana.txt
225
+ - spec/support/active_record_data/4_2_multi.txt
226
+ - spec/support/active_record_data/5_2_multi.txt
227
+ - spec/support/active_record_data/3_2_multi.txt
228
+ - spec/support/active_record_data/4_1_multi.txt
229
+ - spec/support/active_record_data/3_2_diana.txt
230
+ - spec/support/active_record_data/5_0_diana.txt
231
+ - spec/support/active_record_data/6_0_multi.txt
232
+ - spec/support/active_record_data/6_0_diana.txt
233
+ - spec/support/active_record_data/5_1_multi.txt
234
+ - spec/support/active_record_data/5_0_multi.txt
235
+ - spec/support/active_record_data/4_2_diana.txt
236
+ - spec/support/active_record_data/5_1_diana.txt
237
+ - spec/support/active_record_data/4_2_diana_legacy.txt
238
+ - spec/support/active_record_data/5_2_diana.txt
239
+ - spec/support/active_record_data/4_0_diana.txt
240
+ - spec/support/active_record_data/3_2_diana_legacy.txt
241
+ - spec/support/active_record_data/4_2_multi_legacy.txt
242
+ - spec/support/ext_verifier.rb
221
243
  - spec/colors_spec.rb
222
- - spec/formats_spec.rb
223
- - spec/active_record_helper.rb
224
- - spec/objects_spec.rb
244
+ - spec/core_ext/string_spec.rb
245
+ - spec/core_ext/logger_spec.rb
246
+ - spec/ext/active_support_spec.rb
225
247
  - spec/ext/active_record_spec.rb
248
+ - spec/ext/active_model_spec.rb
226
249
  - spec/ext/action_view_spec.rb
227
- - spec/ext/ostruct_spec.rb
250
+ - spec/ext/nobrainer_spec.rb
251
+ - spec/ext/action_controller_spec.rb
252
+ - spec/ext/sequel_spec.rb
228
253
  - spec/ext/mongoid_spec.rb
229
254
  - spec/ext/ripple_spec.rb
230
- - spec/ext/sequel_spec.rb
231
- - spec/ext/active_support_spec.rb
232
- - spec/ext/active_model_spec.rb
255
+ - spec/ext/ostruct_spec.rb
233
256
  - spec/ext/nokogiri_spec.rb
234
257
  - spec/ext/mongo_mapper_spec.rb
235
- - spec/ext/nobrainer_spec.rb
236
- - spec/ext/action_controller_spec.rb
237
- - spec/core_ext/string_spec.rb
238
- - spec/core_ext/logger_spec.rb
239
- - spec/support/mongoid_versions.rb
240
- - spec/support/active_record_data/6_0_diana.txt
241
- - spec/support/active_record_data/4_2_diana.txt
242
- - spec/support/active_record_data/4_2_multi_legacy.txt
243
- - spec/support/active_record_data/3_2_diana.txt
244
- - spec/support/active_record_data/4_0_diana.txt
245
- - spec/support/active_record_data/4_2_diana_legacy.txt
246
- - spec/support/active_record_data/5_1_diana.txt
247
- - spec/support/active_record_data/6_0_multi.txt
248
- - spec/support/active_record_data/3_2_multi_legacy.txt
249
- - spec/support/active_record_data/5_0_multi.txt
250
- - spec/support/active_record_data/5_2_multi.txt
251
- - spec/support/active_record_data/4_2_multi.txt
252
- - spec/support/active_record_data/5_1_multi.txt
253
- - spec/support/active_record_data/4_0_multi.txt
254
- - spec/support/active_record_data/3_2_diana_legacy.txt
255
- - spec/support/active_record_data/4_1_multi.txt
256
- - spec/support/active_record_data/5_2_diana.txt
257
- - spec/support/active_record_data/4_1_diana.txt
258
- - spec/support/active_record_data/3_2_multi.txt
259
- - spec/support/active_record_data/5_0_diana.txt
260
- - spec/support/rails_versions.rb
261
- - spec/support/active_record_data.rb
262
- - spec/support/ext_verifier.rb
263
258
  - spec/sequel_helper.rb
259
+ - spec/formats_spec.rb
260
+ - spec/spec_helper.rb
261
+ - spec/active_record_helper.rb
262
+ - spec/methods_spec.rb
264
263
  - spec/misc_spec.rb
264
+ - spec/objects_spec.rb