amazing_print 1.5.0 → 1.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +68 -38
  3. data/README.md +2 -2
  4. data/lib/amazing_print/core_ext/awesome_method_array.rb +1 -1
  5. data/lib/amazing_print/custom_defaults.rb +7 -1
  6. data/lib/amazing_print/ext/active_record.rb +32 -2
  7. data/lib/amazing_print/ext/mongoid.rb +14 -2
  8. data/lib/amazing_print/ext/nobrainer.rb +2 -2
  9. data/lib/amazing_print/ext_loader.rb +27 -0
  10. data/lib/amazing_print/formatters/base_formatter.rb +12 -3
  11. data/lib/amazing_print/formatters/hash_formatter.rb +28 -11
  12. data/lib/amazing_print/formatters/mswin_helper.rb +4 -4
  13. data/lib/amazing_print/formatters/object_formatter.rb +1 -1
  14. data/lib/amazing_print/formatters/struct_formatter.rb +1 -1
  15. data/lib/amazing_print/inspector.rb +6 -3
  16. data/lib/amazing_print/version.rb +1 -1
  17. data/lib/amazing_print.rb +2 -8
  18. metadata +7 -61
  19. data/.gitignore +0 -35
  20. data/Appraisals +0 -50
  21. data/Gemfile +0 -15
  22. data/Gemfile.lock +0 -83
  23. data/LICENSE +0 -22
  24. data/Rakefile +0 -25
  25. data/spec/active_record_helper.rb +0 -43
  26. data/spec/colors_spec.rb +0 -120
  27. data/spec/core_ext/logger_spec.rb +0 -70
  28. data/spec/ext/action_controller_spec.rb +0 -40
  29. data/spec/ext/action_view_spec.rb +0 -24
  30. data/spec/ext/active_model_spec.rb +0 -37
  31. data/spec/ext/active_record_spec.rb +0 -298
  32. data/spec/ext/active_support_spec.rb +0 -37
  33. data/spec/ext/mongo_mapper_spec.rb +0 -265
  34. data/spec/ext/mongoid_spec.rb +0 -72
  35. data/spec/ext/nobrainer_spec.rb +0 -64
  36. data/spec/ext/nokogiri_spec.rb +0 -52
  37. data/spec/ext/ostruct_spec.rb +0 -24
  38. data/spec/ext/ripple_spec.rb +0 -53
  39. data/spec/ext/sequel_spec.rb +0 -45
  40. data/spec/formats_spec.rb +0 -792
  41. data/spec/methods_spec.rb +0 -520
  42. data/spec/misc_spec.rb +0 -206
  43. data/spec/objects_spec.rb +0 -225
  44. data/spec/sequel_helper.rb +0 -18
  45. data/spec/spec_helper.rb +0 -112
  46. data/spec/support/active_record_data/3_2_diana.txt +0 -24
  47. data/spec/support/active_record_data/3_2_diana_legacy.txt +0 -24
  48. data/spec/support/active_record_data/3_2_multi.txt +0 -50
  49. data/spec/support/active_record_data/3_2_multi_legacy.txt +0 -50
  50. data/spec/support/active_record_data/4_0_diana.txt +0 -98
  51. data/spec/support/active_record_data/4_0_multi.txt +0 -198
  52. data/spec/support/active_record_data/4_1_diana.txt +0 -97
  53. data/spec/support/active_record_data/4_1_multi.txt +0 -196
  54. data/spec/support/active_record_data/4_2_diana.txt +0 -109
  55. data/spec/support/active_record_data/4_2_diana_legacy.txt +0 -109
  56. data/spec/support/active_record_data/4_2_multi.txt +0 -220
  57. data/spec/support/active_record_data/4_2_multi_legacy.txt +0 -220
  58. data/spec/support/active_record_data/5_0_diana.txt +0 -105
  59. data/spec/support/active_record_data/5_0_multi.txt +0 -212
  60. data/spec/support/active_record_data/5_1_diana.txt +0 -104
  61. data/spec/support/active_record_data/5_1_multi.txt +0 -210
  62. data/spec/support/active_record_data/5_2_diana.txt +0 -104
  63. data/spec/support/active_record_data/5_2_multi.txt +0 -210
  64. data/spec/support/active_record_data/6_0_diana.txt +0 -104
  65. data/spec/support/active_record_data/6_0_multi.txt +0 -210
  66. data/spec/support/active_record_data/6_1_diana.txt +0 -109
  67. data/spec/support/active_record_data/6_1_multi.txt +0 -220
  68. data/spec/support/active_record_data.rb +0 -22
  69. data/spec/support/ext_verifier.rb +0 -46
  70. data/spec/support/mongoid_versions.rb +0 -24
  71. data/spec/support/rails_versions.rb +0 -57
data/Appraisals DELETED
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- if RUBY_VERSION < '3'
4
- appraise 'rails-5.2' do
5
- gem 'activerecord-jdbcsqlite3-adapter', '~> 52.0', platform: :jruby
6
- gem 'rails', '~> 5.2.0'
7
- gem 'sqlite3', platform: :mri
8
- end
9
-
10
- appraise 'rails-6.0' do
11
- gem 'activerecord-jdbcsqlite3-adapter', '~> 60.0', platform: :jruby
12
- gem 'rails', '~> 6.0.0'
13
- gem 'sqlite3', platform: :mri
14
- end
15
-
16
- appraise 'mongoid-4.0' do
17
- # https://github.com/rails/rails/issues/34822#issuecomment-570670516
18
- gem 'bigdecimal', '~> 1.4', platforms: :mri
19
- gem 'mongoid', '~> 4.0.0'
20
- end
21
-
22
- appraise 'mongoid-5.0' do
23
- # https://github.com/rails/rails/issues/34822#issuecomment-570670516
24
- gem 'bigdecimal', '~> 1.4', platforms: :mri
25
- gem 'mongoid', '~> 5.0.0'
26
- end
27
-
28
- appraise 'mongoid-6.0' do
29
- gem 'mongoid', '~> 6.0.0'
30
- end
31
-
32
- appraise 'mongo_mapper' do
33
- gem 'activemodel', '~> 4.2.0'
34
- gem 'activesupport', '~> 4.2.0'
35
- gem 'bigdecimal', '~> 1.4', platforms: :mri
36
- gem 'mongo_mapper', '~> 0.14'
37
- end
38
- end
39
-
40
- appraise 'rails-6.1' do
41
- gem 'activerecord-jdbcsqlite3-adapter', '~> 61.0', platform: :jruby
42
- gem 'rails', '~> 6.1.0'
43
- gem 'sqlite3', platform: :mri
44
- end
45
-
46
- appraise 'sequel-5.0' do
47
- gem 'jdbc-sqlite3', platform: :jruby
48
- gem 'sequel', '~> 5.0'
49
- gem 'sqlite3', platform: :mri
50
- end
data/Gemfile DELETED
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- # Specify your gem's dependencies in amazing_print.gemspec
6
- gemspec
7
-
8
- # Development dependencies
9
- gem 'appraisal', '~> 2.3'
10
- gem 'fakefs', '~> 1.2'
11
- gem 'nokogiri', '~> 1.10'
12
- gem 'pry'
13
- gem 'rspec', '~> 3.9'
14
- gem 'rubocop', '~> 1.20'
15
- gem 'rubocop-rspec', '~> 2.4'
data/Gemfile.lock DELETED
@@ -1,83 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- amazing_print (1.5.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- appraisal (2.4.1)
10
- bundler
11
- rake
12
- thor (>= 0.14.0)
13
- ast (2.4.2)
14
- coderay (1.1.3)
15
- diff-lcs (1.5.0)
16
- fakefs (1.9.0)
17
- json (2.6.3)
18
- method_source (1.0.0)
19
- nokogiri (1.15.2-x86_64-linux)
20
- racc (~> 1.4)
21
- parallel (1.23.0)
22
- parser (3.2.2.1)
23
- ast (~> 2.4.1)
24
- pry (0.14.2)
25
- coderay (~> 1.1)
26
- method_source (~> 1.0)
27
- racc (1.6.2)
28
- rainbow (3.1.1)
29
- rake (13.0.6)
30
- regexp_parser (2.8.0)
31
- rexml (3.2.5)
32
- rspec (3.12.0)
33
- rspec-core (~> 3.12.0)
34
- rspec-expectations (~> 3.12.0)
35
- rspec-mocks (~> 3.12.0)
36
- rspec-core (3.12.2)
37
- rspec-support (~> 3.12.0)
38
- rspec-expectations (3.12.3)
39
- diff-lcs (>= 1.2.0, < 2.0)
40
- rspec-support (~> 3.12.0)
41
- rspec-mocks (3.12.5)
42
- diff-lcs (>= 1.2.0, < 2.0)
43
- rspec-support (~> 3.12.0)
44
- rspec-support (3.12.0)
45
- rubocop (1.51.0)
46
- json (~> 2.3)
47
- parallel (~> 1.10)
48
- parser (>= 3.2.0.0)
49
- rainbow (>= 2.2.2, < 4.0)
50
- regexp_parser (>= 1.8, < 3.0)
51
- rexml (>= 3.2.5, < 4.0)
52
- rubocop-ast (>= 1.28.0, < 2.0)
53
- ruby-progressbar (~> 1.7)
54
- unicode-display_width (>= 2.4.0, < 3.0)
55
- rubocop-ast (1.28.1)
56
- parser (>= 3.2.1.0)
57
- rubocop-capybara (2.18.0)
58
- rubocop (~> 1.41)
59
- rubocop-factory_bot (2.23.1)
60
- rubocop (~> 1.33)
61
- rubocop-rspec (2.22.0)
62
- rubocop (~> 1.33)
63
- rubocop-capybara (~> 2.17)
64
- rubocop-factory_bot (~> 2.22)
65
- ruby-progressbar (1.13.0)
66
- thor (1.2.2)
67
- unicode-display_width (2.4.2)
68
-
69
- PLATFORMS
70
- x86_64-linux
71
-
72
- DEPENDENCIES
73
- amazing_print!
74
- appraisal (~> 2.3)
75
- fakefs (~> 1.2)
76
- nokogiri (~> 1.10)
77
- pry
78
- rspec (~> 3.9)
79
- rubocop (~> 1.20)
80
- rubocop-rspec (~> 2.4)
81
-
82
- BUNDLED WITH
83
- 2.3.12
data/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2010-2019 Michael Dvorkin
4
- Copyright (c) 2020 AmazingPrint
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in all
14
- copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- SOFTWARE.
data/Rakefile DELETED
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rubygems'
4
- require 'bundler/setup'
5
-
6
- require 'bundler'
7
- Bundler::GemHelper.install_tasks
8
-
9
- task :default do
10
- if ENV['BUNDLE_GEMFILE'] =~ /gemfiles/
11
- Rake::Task['spec'].invoke
12
- else
13
- Rake::Task['appraise'].invoke
14
- end
15
- end
16
-
17
- task :appraise do
18
- exec 'appraisal install && appraisal rake'
19
- end
20
-
21
- desc 'Run all amazing_print gem specs'
22
- task :spec do
23
- # Run plain rspec command without RSpec::Core::RakeTask overrides.
24
- exec 'rspec -c spec'
25
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- if ExtVerifier.has_rails?
4
- # Required to use the column support
5
- module Rails
6
- def self.env
7
- {}
8
- end
9
- end
10
-
11
- # Establish connection to in-memory SQLite DB
12
- ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
13
-
14
- # Create the users table
15
- ActiveRecord::Migration.verbose = false
16
- ActiveRecord::Migration.create_table :users do |t|
17
- t.string :name
18
- t.integer :rank
19
- t.boolean :admin
20
- t.datetime :created_at
21
- end
22
-
23
- ActiveRecord::Migration.create_table :emails do |t|
24
- t.references :user
25
- t.string :email_address
26
- end
27
-
28
- # Create models
29
- class User < ActiveRecord::Base; has_many :emails; end
30
-
31
- class SubUser < User; end
32
-
33
- class Email < ActiveRecord::Base; belongs_to :user; end
34
-
35
- class TableFreeModel
36
- include ::ActiveModel::Validations
37
- attr_reader(:name)
38
-
39
- def attributes
40
- { 'name' => name }
41
- end
42
- end
43
- end
data/spec/colors_spec.rb DELETED
@@ -1,120 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # rubocop:disable Lint/ConstantDefinitionInBlock, Style/OptionalBooleanParameter
4
-
5
- require 'spec_helper'
6
-
7
- RSpec.describe 'AmazingPrint' do
8
- def stub_tty!(output = true, stream = $stdout)
9
- if output
10
- stream.instance_eval do
11
- def tty?
12
- true
13
- end
14
- end
15
- else
16
- stream.instance_eval do
17
- def tty?
18
- false
19
- end
20
- end
21
- end
22
- end
23
-
24
- describe 'colorization' do
25
- PLAIN = '[ 1, :two, "three", [ nil, [ true, false ] ] ]'
26
- COLORIZED = "[ \e[1;34m1\e[0m, \e[0;36m:two\e[0m, \e[0;33m\"three\"\e[0m, [ \e[1;31mnil\e[0m, [ \e[1;32mtrue\e[0m, \e[1;31mfalse\e[0m ] ] ]"
27
-
28
- before do
29
- ENV['TERM'] = 'xterm-colors'
30
- ENV.delete('ANSICON')
31
- @arr = [1, :two, 'three', [nil, [true, false]]]
32
- end
33
-
34
- describe 'default settings (no forced colors)' do
35
- before do
36
- AmazingPrint.force_colors! colors: false
37
- end
38
-
39
- it 'colorizes tty processes by default' do
40
- stub_tty!
41
- expect(@arr.ai(multiline: false)).to eq(COLORIZED)
42
- end
43
-
44
- it "colorizes processes with ENV['ANSICON'] by default" do
45
- stub_tty!
46
- term = ENV['ANSICON']
47
- ENV['ANSICON'] = '1'
48
- expect(@arr.ai(multiline: false)).to eq(COLORIZED)
49
- ensure
50
- ENV['ANSICON'] = term
51
- end
52
-
53
- it 'does not colorize tty processes running in dumb terminals by default' do
54
- stub_tty!
55
- term = ENV['TERM']
56
- ENV['TERM'] = 'dumb'
57
- expect(@arr.ai(multiline: false)).to eq(PLAIN)
58
- ensure
59
- ENV['TERM'] = term
60
- end
61
-
62
- it 'does not colorize subprocesses by default' do
63
- stub_tty! false
64
- expect(@arr.ai(multiline: false)).to eq(PLAIN)
65
- ensure
66
- stub_tty!
67
- end
68
- end
69
-
70
- describe 'forced colors override' do
71
- before do
72
- AmazingPrint.force_colors!
73
- end
74
-
75
- it 'still colorizes tty processes' do
76
- stub_tty!
77
- expect(@arr.ai(multiline: false)).to eq(COLORIZED)
78
- end
79
-
80
- it "colorizes processes with ENV['ANSICON'] set to 0" do
81
- stub_tty!
82
- term = ENV['ANSICON']
83
- ENV['ANSICON'] = '1'
84
- expect(@arr.ai(multiline: false)).to eq(COLORIZED)
85
- ensure
86
- ENV['ANSICON'] = term
87
- end
88
-
89
- it 'colorizes dumb terminals' do
90
- stub_tty!
91
- term = ENV['TERM']
92
- ENV['TERM'] = 'dumb'
93
- expect(@arr.ai(multiline: false)).to eq(COLORIZED)
94
- ensure
95
- ENV['TERM'] = term
96
- end
97
-
98
- it 'colorizes subprocess' do
99
- stub_tty! false
100
- expect(@arr.ai(multiline: false)).to eq(COLORIZED)
101
- ensure
102
- stub_tty!
103
- end
104
- end
105
- end
106
-
107
- describe 'AmazingPrint::Colors' do
108
- %i[gray red green yellow blue purple cyan white].each_with_index do |color, i|
109
- it "has #{color} color" do
110
- expect(AmazingPrint::Colors.public_send(color, color.to_s)).to eq("\e[1;#{i + 30}m#{color}\e[0m")
111
- end
112
-
113
- it "has #{color}ish color" do
114
- expect(AmazingPrint::Colors.public_send(:"#{color}ish", color.to_s)).to eq("\e[0;#{i + 30}m#{color}\e[0m")
115
- end
116
- end
117
- end
118
- end
119
-
120
- # rubocop:enable Lint/ConstantDefinitionInBlock, Style/OptionalBooleanParameter
@@ -1,70 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- require 'logger'
6
- require 'amazing_print/core_ext/logger'
7
-
8
- RSpec.describe 'AmazingPrint logging extensions' do
9
- subject(:logger) do
10
- Logger.new('/dev/null')
11
- rescue Errno::ENOENT
12
- Logger.new('nul')
13
- end
14
-
15
- let(:object) { double }
16
- let(:options) { { sort_keys: true } }
17
-
18
- describe 'ap method' do
19
- it 'awesome_inspects the given object' do
20
- expect(object).to receive(:ai)
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
27
- end
28
-
29
- describe 'the log level' do
30
- before do
31
- AmazingPrint.defaults = {}
32
- end
33
-
34
- it 'fallbacks to the default :debug log level' do
35
- expect(logger).to receive(:debug)
36
- logger.ap nil
37
- end
38
-
39
- it 'uses the global user default if no level passed' do
40
- AmazingPrint.defaults = { log_level: :info }
41
- expect(logger).to receive(:info)
42
- logger.ap nil
43
- end
44
-
45
- it 'uses the passed in level' do
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
67
- end
68
- end
69
- end
70
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'AmazingPrint::ActionController', skip: -> { !ExtVerifier.has_rails? }.call do
6
- let(:inspector) { AmazingPrint::Inspector.new }
7
-
8
- context 'with unpermitted ActionController::Parameters' do
9
- let(:parameters) do
10
- ActionController::Parameters.new post: { id: 1, content: 'Some' }
11
- end
12
-
13
- it 'formats as an object' do
14
- expect(inspector.send(:awesome, parameters)).to match(
15
- /\A#?<ActionController::Parameters {"post"=>{"id"=>1, "content"=>"Some"}} permitted: false>\z/
16
- )
17
- end
18
- end
19
-
20
- context 'with permitted ActionController::Parameters' do
21
- let(:expected_output) do
22
- <<~OUTPUT
23
- {
24
- "post"\e[0;37m => \e[0m{
25
- "id"\e[0;37m => \e[0m\e[1;34m1\e[0m,
26
- "content"\e[0;37m => \e[0m\e[0;33m"Some"\e[0m
27
- }
28
- }
29
- OUTPUT
30
- .chomp
31
- end
32
- let(:parameters) do
33
- ActionController::Parameters.new post: { id: 1, content: 'Some' }
34
- end
35
-
36
- it 'formats as a hash' do
37
- expect(inspector.send(:awesome, parameters.permit!)).to eq expected_output
38
- end
39
- end
40
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'AmazingPrint ActionView extensions',
6
- skip: -> { !ExtVerifier.has_rails? || ActiveRecord::VERSION::STRING >= '6.1' }.call do
7
- before do
8
- @view = ActionView::Base.new
9
- end
10
-
11
- it "uses HTML and adds 'debug_dump' class to plain <pre> tag" do
12
- markup = rand
13
- expect(@view.ap(markup, plain: true)).to eq(%(<pre class="debug_dump">#{markup}</pre>))
14
- end
15
-
16
- it "uses HTML and adds 'debug_dump' class to colorized <pre> tag" do
17
- markup = ' &<hello>'
18
- expect(@view.ap(markup)).to eq('<pre class="debug_dump"><kbd style="color:brown">&quot; &amp;&lt;hello&gt;&quot;</kbd></pre>')
19
- end
20
-
21
- it 'uses HTML and does set output to HTML safe' do
22
- expect(@view.ap('<p>Hello World</p>')).to be_html_safe
23
- end
24
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'active_record_helper'
5
-
6
- RSpec.describe 'ActiveModel::Errors formatting', skip: -> { !ExtVerifier.has_rails? }.call do
7
- before do
8
- @ap = AmazingPrint::Inspector.new(plain: true)
9
- end
10
-
11
- it 'formats active_model_errors properly' do
12
- model = TableFreeModel.new
13
- model.errors.add(:name, "can't be blank")
14
-
15
- out = @ap.awesome(model.errors)
16
-
17
- str = <<~ERRORS.strip
18
- #<ActiveModel::Errors:placeholder_id> {
19
- "name" => nil,
20
- :details => {
21
- :name => [
22
- [0] {
23
- :error => "can't be blank"
24
- }
25
- ]
26
- },
27
- :messages => {
28
- :name => [
29
- [0] "can't be blank"
30
- ]
31
- }
32
- }
33
- ERRORS
34
-
35
- expect(out).to be_similar_to(str)
36
- end
37
- end