amazing_print 1.2.0 → 1.4.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/Appraisals +38 -54
- data/CHANGELOG.md +36 -2
- data/Gemfile.lock +48 -50
- data/README.md +20 -11
- data/lib/amazing_print/colorize.rb +1 -3
- data/lib/amazing_print/core_ext/awesome_method_array.rb +4 -4
- data/lib/amazing_print/core_ext/class.rb +1 -1
- data/lib/amazing_print/core_ext/logger.rb +10 -5
- data/lib/amazing_print/core_ext/object.rb +1 -1
- data/lib/amazing_print/custom_defaults.rb +10 -3
- data/lib/amazing_print/ext/action_view.rb +1 -1
- data/lib/amazing_print/ext/active_record.rb +12 -27
- data/lib/amazing_print/ext/active_support.rb +1 -3
- data/lib/amazing_print/ext/mongo_mapper.rb +5 -8
- data/lib/amazing_print/ext/mongoid.rb +2 -6
- data/lib/amazing_print/ext/nobrainer.rb +7 -5
- data/lib/amazing_print/ext/nokogiri.rb +1 -3
- data/lib/amazing_print/ext/ostruct.rb +1 -3
- data/lib/amazing_print/ext/ripple.rb +4 -5
- data/lib/amazing_print/formatter.rb +5 -6
- data/lib/amazing_print/formatters/array_formatter.rb +6 -5
- data/lib/amazing_print/formatters/base_formatter.rb +20 -25
- data/lib/amazing_print/formatters/class_formatter.rb +1 -0
- data/lib/amazing_print/formatters/dir_formatter.rb +1 -0
- data/lib/amazing_print/formatters/file_formatter.rb +1 -0
- data/lib/amazing_print/formatters/hash_formatter.rb +5 -4
- data/lib/amazing_print/formatters/method_formatter.rb +1 -0
- data/lib/amazing_print/formatters/object_formatter.rb +2 -1
- data/lib/amazing_print/formatters/simple_formatter.rb +1 -0
- data/lib/amazing_print/formatters/struct_formatter.rb +2 -1
- data/lib/amazing_print/inspector.rb +29 -5
- data/lib/amazing_print/version.rb +1 -1
- data/lib/amazing_print.rb +2 -6
- data/spec/active_record_helper.rb +11 -0
- data/spec/colors_spec.rb +38 -46
- data/spec/core_ext/logger_spec.rb +42 -18
- data/spec/core_ext/string_spec.rb +2 -2
- data/spec/ext/action_controller_spec.rb +4 -4
- data/spec/ext/action_view_spec.rb +6 -1
- data/spec/ext/active_model_spec.rb +37 -0
- data/spec/ext/active_record_spec.rb +44 -23
- data/spec/ext/active_support_spec.rb +13 -4
- data/spec/ext/mongo_mapper_spec.rb +16 -12
- data/spec/ext/mongoid_spec.rb +7 -3
- data/spec/ext/nobrainer_spec.rb +6 -2
- data/spec/ext/nokogiri_spec.rb +3 -3
- data/spec/ext/ripple_spec.rb +6 -2
- data/spec/formats_spec.rb +24 -18
- data/spec/methods_spec.rb +12 -4
- data/spec/misc_spec.rb +15 -10
- data/spec/objects_spec.rb +4 -0
- data/spec/spec_helper.rb +4 -8
- data/spec/support/active_record_data/6_1_diana.txt +109 -0
- data/spec/support/active_record_data/6_1_multi.txt +220 -0
- data/spec/support/ext_verifier.rb +2 -4
- data/spec/support/rails_versions.rb +5 -0
- metadata +80 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95f05f3413c3497f346ec0bb7de2ed94a065aa6224a0a6bc8b36c699728ea4b2
|
4
|
+
data.tar.gz: 112760cadb1e3b76240163a64a462323975e5885ea0e002845790d75fb0c6858
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f2e2fddf5cbf25953721ab0bc8f0ff0648fbe93710508137af6022ef5b8c5153be9292cbea2910fe4ef8b434c2a3510585f2ef5e98097296f78e0c74f292140
|
7
|
+
data.tar.gz: 0b2e88771d4c2835e586a5ccf5c3c6e8822267475a65ddd80faf5908e526b099ea888953395fb77047df776ba7f6e7e63cf8bf50cb7676b253b2c67987b1437c
|
data/Appraisals
CHANGED
@@ -1,66 +1,50 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
21
38
|
end
|
22
39
|
|
23
|
-
appraise 'rails-6.
|
24
|
-
gem 'activerecord-jdbcsqlite3-adapter', '~>
|
25
|
-
gem 'rails', '~> 6.
|
40
|
+
appraise 'rails-6.1' do
|
41
|
+
gem 'activerecord-jdbcsqlite3-adapter', '~> 61.0', platform: :jruby
|
42
|
+
gem 'rails', '~> 6.1.0'
|
26
43
|
gem 'sqlite3', platform: :mri
|
27
44
|
end
|
28
45
|
|
29
|
-
appraise 'mongoid-4.0' do
|
30
|
-
# https://github.com/rails/rails/issues/34822#issuecomment-570670516
|
31
|
-
gem 'bigdecimal', '~> 1.4', platforms: :mri
|
32
|
-
gem 'mongoid', '~> 4.0.0'
|
33
|
-
end
|
34
|
-
|
35
|
-
appraise 'mongoid-5.0' do
|
36
|
-
# https://github.com/rails/rails/issues/34822#issuecomment-570670516
|
37
|
-
gem 'bigdecimal', '~> 1.4', platforms: :mri
|
38
|
-
gem 'mongoid', '~> 5.0.0'
|
39
|
-
end
|
40
|
-
|
41
|
-
appraise 'mongoid-6.0' do
|
42
|
-
gem 'mongoid', '~> 6.0.0'
|
43
|
-
end
|
44
|
-
|
45
46
|
appraise 'sequel-5.0' do
|
46
47
|
gem 'jdbc-sqlite3', platform: :jruby
|
47
48
|
gem 'sequel', '~> 5.0'
|
48
49
|
gem 'sqlite3', platform: :mri
|
49
50
|
end
|
50
|
-
|
51
|
-
# appraise 'mongo_mapper' do
|
52
|
-
# gem 'mongo_mapper'
|
53
|
-
# end
|
54
|
-
#
|
55
|
-
# appraise 'ripple' do
|
56
|
-
# gem 'tzinfo'
|
57
|
-
# gem 'ripple'
|
58
|
-
# end
|
59
|
-
#
|
60
|
-
# appraise 'nobrainer' do
|
61
|
-
# gem 'nobrainer'
|
62
|
-
#
|
63
|
-
# # When activesupport 5 was released, it required ruby 2.2.2 as a minimum.
|
64
|
-
# # Locking this down to 4.2.6 allows our Ruby 1.9 tests to keep working.
|
65
|
-
# gem 'activesupport', '4.2.6', :platforms => :ruby_19
|
66
|
-
# end
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,39 @@
|
|
1
|
-
##
|
2
|
-
|
1
|
+
## Unreleased
|
2
|
+
|
3
|
+
## v1.4.0
|
4
|
+
- Support loading config from `$XDG_CONFIG_HOME/aprc` - #63
|
5
|
+
- Remove support for Rails 5.1 #75
|
6
|
+
- Update AR specs for Ruby 2.6.7 #76
|
7
|
+
- Load .aprc configs only once. #74
|
8
|
+
- Add XDG config support #77
|
9
|
+
- Rubocop updates #79
|
10
|
+
- Update Irb integration for v1.2.6+ #81
|
11
|
+
|
12
|
+
## v1.3.0
|
13
|
+
- Fix HTML escaping problems #53
|
14
|
+
- Update test suite for Ruby 2.7.2 and JRuby #61
|
15
|
+
- Add ActionView spec for html_safe #65
|
16
|
+
- Add support for Rails 6.1 #68
|
17
|
+
- Update specs for Ruby 3.0 #69
|
18
|
+
|
19
|
+
## v1.2.2
|
20
|
+
- Support Ruby 3.0 / IRB 1.2.6 - #57
|
21
|
+
- Fix FrozenError - #51
|
22
|
+
- Drop support for Ruby 2.3 and 2.4 as well as JRuby 9.1 - #46
|
23
|
+
- Add passing of `options` to `Logger#ap` - #55
|
24
|
+
|
25
|
+
## v1.2.1
|
26
|
+
- Correctly print active_model_errors for models that don't have tables - #42 by sahglie
|
27
|
+
- Update AmazingPrint::MongoMapper for frozen strings - #44
|
28
|
+
|
29
|
+
## v1.2.0
|
30
|
+
|
31
|
+
- Fix frozen string literal issue with ActiveRecord
|
32
|
+
- Add uncolor String method to remove ANSI color codes - #30 by duffyjp
|
33
|
+
- Restore original copyright - #33 by amarshall
|
34
|
+
- Remove method core extension since it is not needed since ruby 1.9 - #37 by grosser
|
35
|
+
- Remove pale and black string color aliases - #38
|
36
|
+
- Fix formatting ActionController::Parameters - #29
|
3
37
|
|
4
38
|
|
5
39
|
## v1.1.0
|
data/Gemfile.lock
CHANGED
@@ -1,79 +1,77 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
amazing_print (1.1.
|
4
|
+
amazing_print (1.3.1.pre)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
appraisal (2.
|
9
|
+
appraisal (2.4.1)
|
10
10
|
bundler
|
11
11
|
rake
|
12
12
|
thor (>= 0.14.0)
|
13
|
-
ast (2.4.
|
14
|
-
coderay (1.1.
|
15
|
-
diff-lcs (1.
|
16
|
-
fakefs (1.2
|
17
|
-
ffi (1.12.2-java)
|
18
|
-
jaro_winkler (1.5.4)
|
19
|
-
jaro_winkler (1.5.4-java)
|
13
|
+
ast (2.4.2)
|
14
|
+
coderay (1.1.3)
|
15
|
+
diff-lcs (1.4.4)
|
16
|
+
fakefs (1.3.2)
|
20
17
|
method_source (1.0.0)
|
21
|
-
mini_portile2 (2.
|
22
|
-
nokogiri (1.
|
23
|
-
mini_portile2 (~> 2.
|
24
|
-
|
25
|
-
parallel (1.
|
26
|
-
parser (
|
27
|
-
ast (~> 2.4.
|
28
|
-
pry (0.
|
18
|
+
mini_portile2 (2.6.1)
|
19
|
+
nokogiri (1.12.5)
|
20
|
+
mini_portile2 (~> 2.6.1)
|
21
|
+
racc (~> 1.4)
|
22
|
+
parallel (1.21.0)
|
23
|
+
parser (3.0.2.0)
|
24
|
+
ast (~> 2.4.1)
|
25
|
+
pry (0.14.1)
|
29
26
|
coderay (~> 1.1)
|
30
27
|
method_source (~> 1.0)
|
31
|
-
|
32
|
-
coderay (~> 1.1)
|
33
|
-
method_source (~> 1.0)
|
34
|
-
spoon (~> 0.0)
|
28
|
+
racc (1.5.2)
|
35
29
|
rainbow (3.0.0)
|
36
|
-
rake (13.0.
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
rspec-
|
41
|
-
rspec-
|
42
|
-
|
43
|
-
|
44
|
-
|
30
|
+
rake (13.0.6)
|
31
|
+
regexp_parser (2.1.1)
|
32
|
+
rexml (3.2.5)
|
33
|
+
rspec (3.10.0)
|
34
|
+
rspec-core (~> 3.10.0)
|
35
|
+
rspec-expectations (~> 3.10.0)
|
36
|
+
rspec-mocks (~> 3.10.0)
|
37
|
+
rspec-core (3.10.1)
|
38
|
+
rspec-support (~> 3.10.0)
|
39
|
+
rspec-expectations (3.10.1)
|
45
40
|
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
-
rspec-support (~> 3.
|
47
|
-
rspec-mocks (3.
|
41
|
+
rspec-support (~> 3.10.0)
|
42
|
+
rspec-mocks (3.10.2)
|
48
43
|
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
-
rspec-support (~> 3.
|
50
|
-
rspec-support (3.
|
51
|
-
rubocop (
|
52
|
-
jaro_winkler (~> 1.5.1)
|
44
|
+
rspec-support (~> 3.10.0)
|
45
|
+
rspec-support (3.10.2)
|
46
|
+
rubocop (1.22.1)
|
53
47
|
parallel (~> 1.10)
|
54
|
-
parser (>=
|
48
|
+
parser (>= 3.0.0.0)
|
55
49
|
rainbow (>= 2.2.2, < 4.0)
|
50
|
+
regexp_parser (>= 1.8, < 3.0)
|
56
51
|
rexml
|
52
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
57
53
|
ruby-progressbar (~> 1.7)
|
58
|
-
unicode-display_width (>= 1.4.0, <
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
54
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
55
|
+
rubocop-ast (1.12.0)
|
56
|
+
parser (>= 3.0.1.1)
|
57
|
+
rubocop-rspec (2.5.0)
|
58
|
+
rubocop (~> 1.19)
|
59
|
+
ruby-progressbar (1.11.0)
|
60
|
+
thor (1.1.0)
|
61
|
+
unicode-display_width (2.1.0)
|
64
62
|
|
65
63
|
PLATFORMS
|
66
|
-
java
|
67
64
|
ruby
|
68
65
|
|
69
66
|
DEPENDENCIES
|
70
67
|
amazing_print!
|
71
|
-
appraisal
|
72
|
-
fakefs (
|
73
|
-
nokogiri (
|
68
|
+
appraisal (~> 2.3)
|
69
|
+
fakefs (~> 1.2)
|
70
|
+
nokogiri (~> 1.10)
|
74
71
|
pry
|
75
|
-
rspec (
|
76
|
-
rubocop (~>
|
72
|
+
rspec (~> 3.9)
|
73
|
+
rubocop (~> 1.20)
|
74
|
+
rubocop-rspec (~> 2.4)
|
77
75
|
|
78
76
|
BUNDLED WITH
|
79
|
-
2.
|
77
|
+
2.2.27
|
data/README.md
CHANGED
@@ -9,14 +9,14 @@
|
|
9
9
|
|
|
10
10
|
[](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
|
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
|

|
15
15
|
|
16
16
|
### Supported Versions ###
|
17
17
|
|
18
|
-
- Ruby >= 2.
|
19
|
-
- Rails >= 5.
|
18
|
+
- Ruby >= 2.5
|
19
|
+
- Rails >= 5.2
|
20
20
|
|
21
21
|
### Installation ###
|
22
22
|
# Installing as Ruby gem
|
@@ -48,7 +48,7 @@ ruby19_syntax: false, # Use Ruby 1.9 hash syntax in output.
|
|
48
48
|
class_name: :class, # Method called to report the instance class name. (e.g. :to_s)
|
49
49
|
object_id: true, # Show object id.
|
50
50
|
color: {
|
51
|
-
args: :
|
51
|
+
args: :whiteish,
|
52
52
|
array: :white,
|
53
53
|
bigdecimal: :blue,
|
54
54
|
class: :yellow,
|
@@ -56,13 +56,13 @@ color: {
|
|
56
56
|
falseclass: :red,
|
57
57
|
integer: :blue,
|
58
58
|
float: :blue,
|
59
|
-
hash: :
|
59
|
+
hash: :whiteish,
|
60
60
|
keyword: :cyan,
|
61
61
|
method: :purpleish,
|
62
62
|
nilclass: :red,
|
63
63
|
rational: :blue,
|
64
64
|
string: :yellowish,
|
65
|
-
struct: :
|
65
|
+
struct: :whiteish,
|
66
66
|
symbol: :cyanish,
|
67
67
|
time: :greenish,
|
68
68
|
trueclass: :green,
|
@@ -74,7 +74,7 @@ Supported color names:
|
|
74
74
|
|
75
75
|
```ruby
|
76
76
|
:gray, :red, :green, :yellow, :blue, :purple, :cyan, :white
|
77
|
-
:
|
77
|
+
:grayish, :redish, :greenish, :yellowish, :blueish, :purpleish, :cyanish, :whiteish
|
78
78
|
```
|
79
79
|
|
80
80
|
Use `Object#ai` to return an ASCII encoded string:
|
@@ -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
|
@@ -319,21 +325,24 @@ red text # (it's red)
|
|
319
325
|
```
|
320
326
|
|
321
327
|
### Setting Custom Defaults ###
|
322
|
-
You can set your own default options by creating
|
323
|
-
directory. Within that file assign your
|
328
|
+
You can set your own default options by creating ``aprc`` file in your `$XDG_CONFIG_HOME`
|
329
|
+
directory (defaults to `~/.config` if undefined). Within that file assign your defaults
|
330
|
+
to ``AmazingPrint.defaults``.
|
324
331
|
For example:
|
325
332
|
|
326
333
|
```ruby
|
327
|
-
# ~/.aprc file.
|
334
|
+
# ~/.config/aprc file.
|
328
335
|
AmazingPrint.defaults = {
|
329
336
|
:indent => -2,
|
330
337
|
:color => {
|
331
|
-
:hash => :
|
338
|
+
:hash => :whiteish,
|
332
339
|
:class => :white
|
333
340
|
}
|
334
341
|
}
|
335
342
|
```
|
336
343
|
|
344
|
+
The previous `~/.aprc` location is still supported as fallback.
|
345
|
+
|
337
346
|
## Versioning
|
338
347
|
|
339
348
|
AmazingPrint follows the [Semantic Versioning](http://semver.org/) standard.
|
@@ -17,9 +17,7 @@ module AmazingPrint
|
|
17
17
|
elsif str.method(options[:color][type]).arity == -1 # Accepts html parameter.
|
18
18
|
str.send(options[:color][type], options[:html])
|
19
19
|
else
|
20
|
-
if options[:html]
|
21
|
-
str = %(<kbd style="color:#{options[:color][type]}">#{str}</kbd>)
|
22
|
-
end
|
20
|
+
str = %(<kbd style="color:#{options[:color][type]}">#{str}</kbd>) if options[:html]
|
23
21
|
str.send(options[:color][type])
|
24
22
|
end
|
25
23
|
end
|
@@ -14,14 +14,14 @@
|
|
14
14
|
#
|
15
15
|
# If you could think of a better way please let me know :-)
|
16
16
|
#
|
17
|
-
module AwesomeMethodArray
|
18
|
-
def -(
|
17
|
+
module AwesomeMethodArray # :nodoc:
|
18
|
+
def -(other)
|
19
19
|
super.tap do |arr|
|
20
20
|
arr.instance_variable_set(:@__awesome_methods__, instance_variable_get(:@__awesome_methods__))
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def &(
|
24
|
+
def &(other)
|
25
25
|
super.tap do |arr|
|
26
26
|
arr.instance_variable_set(:@__awesome_methods__, instance_variable_get(:@__awesome_methods__))
|
27
27
|
end
|
@@ -68,7 +68,7 @@ module AwesomeMethodArray #:nodoc:
|
|
68
68
|
# [ 0, 1, 2, 3, 4 ].grep(1..2, &:succ)
|
69
69
|
#
|
70
70
|
begin
|
71
|
-
eval("%Q/#{match.to_s.gsub('/', '\/')}/ =~ #{pattern.inspect}", blk.binding)
|
71
|
+
eval("%Q/#{match.to_s.gsub('/', '\/')}/ =~ #{pattern.inspect}", blk.binding, __FILE__, __LINE__)
|
72
72
|
rescue StandardError
|
73
73
|
ArgumentError
|
74
74
|
end
|
@@ -5,7 +5,7 @@
|
|
5
5
|
# AmazingPrint is freely distributable under the terms of MIT license.
|
6
6
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
7
7
|
#------------------------------------------------------------------------------
|
8
|
-
class Class
|
8
|
+
class Class # :nodoc:
|
9
9
|
#
|
10
10
|
# Intercept methods below to inject @__amazing_print__ instance variable
|
11
11
|
# so we know it is the *methods* array when formatting an array.
|
@@ -9,15 +9,20 @@ module AmazingPrint
|
|
9
9
|
module Logger
|
10
10
|
# Add ap method to logger
|
11
11
|
#------------------------------------------------------------------------------
|
12
|
-
def ap(object,
|
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
|
19
26
|
|
20
27
|
Logger.include AmazingPrint::Logger
|
21
|
-
if defined?(ActiveSupport::BufferedLogger)
|
22
|
-
ActiveSupport::BufferedLogger.include AmazingPrint::Logger
|
23
|
-
end
|
28
|
+
ActiveSupport::BufferedLogger.include AmazingPrint::Logger if defined?(ActiveSupport::BufferedLogger)
|
@@ -5,7 +5,7 @@
|
|
5
5
|
# AmazingPrint is freely distributable under the terms of MIT license.
|
6
6
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
7
7
|
#------------------------------------------------------------------------------
|
8
|
-
class Object
|
8
|
+
class Object # :nodoc:
|
9
9
|
#
|
10
10
|
# Intercept methods below to inject @__amazing_print__ instance variable
|
11
11
|
# so we know it is the *methods* array when formatting an array.
|
@@ -7,8 +7,8 @@ module AmazingPrint
|
|
7
7
|
# Class accessor to force colorized output (ex. forked subprocess where TERM
|
8
8
|
# might be dumb).
|
9
9
|
#---------------------------------------------------------------------------
|
10
|
-
def force_colors!(
|
11
|
-
@force_colors =
|
10
|
+
def force_colors!(colors: true)
|
11
|
+
@force_colors = colors
|
12
12
|
end
|
13
13
|
|
14
14
|
def console?
|
@@ -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) # rubocop:disable Style/OptionalBooleanParameter
|
33
33
|
ap @context.last_value
|
34
34
|
rescue NoMethodError
|
35
35
|
puts "(Object doesn't support #ai)"
|
@@ -47,6 +47,13 @@ module AmazingPrint
|
|
47
47
|
Pry.print = proc { |output, value| output.puts value.ai } if defined?(Pry)
|
48
48
|
end
|
49
49
|
|
50
|
+
##
|
51
|
+
# Reload the cached custom configurations.
|
52
|
+
#
|
53
|
+
def reload!
|
54
|
+
AmazingPrint::Inspector.reload_dotfile
|
55
|
+
end
|
56
|
+
|
50
57
|
private
|
51
58
|
|
52
59
|
# Takes a value and returns true unless it is false or nil
|
@@ -45,37 +45,30 @@ module AmazingPrint
|
|
45
45
|
return object.inspect unless defined?(::ActiveSupport::OrderedHash)
|
46
46
|
return awesome_object(object) if @options[:raw]
|
47
47
|
|
48
|
-
data = if object.class.column_names
|
49
|
-
object.attributes
|
50
|
-
else
|
48
|
+
data = if object.class.column_names == object.attributes.keys
|
51
49
|
object.class.column_names.each_with_object(::ActiveSupport::OrderedHash.new) do |name, hash|
|
52
50
|
if object.has_attribute?(name) || object.new_record?
|
53
51
|
value = object.respond_to?(name) ? object.send(name) : object.read_attribute(name)
|
54
52
|
hash[name.to_sym] = value
|
55
53
|
end
|
56
54
|
end
|
55
|
+
else
|
56
|
+
object.attributes
|
57
57
|
end
|
58
|
-
|
58
|
+
[awesome_simple(object.to_s, :active_record_instance), awesome_hash(data)].join(' ')
|
59
59
|
end
|
60
60
|
|
61
61
|
# Format ActiveRecord class object.
|
62
62
|
#------------------------------------------------------------------------------
|
63
63
|
def awesome_active_record_class(object)
|
64
|
-
if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:columns) || object.to_s == 'ActiveRecord::Base'
|
65
|
-
|
66
|
-
end
|
67
|
-
if object.respond_to?(:abstract_class?) && object.abstract_class?
|
68
|
-
return awesome_class(object)
|
69
|
-
end
|
64
|
+
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:columns) || object.to_s == 'ActiveRecord::Base'
|
65
|
+
return awesome_class(object) if object.respond_to?(:abstract_class?) && object.abstract_class?
|
70
66
|
|
71
67
|
data = object.columns.each_with_object(::ActiveSupport::OrderedHash.new) do |c, hash|
|
72
68
|
hash[c.name.to_sym] = c.type
|
73
69
|
end
|
74
70
|
|
75
|
-
|
76
|
-
base = "< #{awesome_simple(object.superclass.to_s, :class)}"
|
77
|
-
|
78
|
-
[name, base, awesome_hash(data)].join(' ')
|
71
|
+
[awesome_simple("class #{object} < #{object.superclass}", :class), awesome_hash(data)].join(' ')
|
79
72
|
end
|
80
73
|
|
81
74
|
# Format ActiveModel error object.
|
@@ -84,20 +77,12 @@ module AmazingPrint
|
|
84
77
|
return object.inspect unless defined?(::ActiveSupport::OrderedHash)
|
85
78
|
return awesome_object(object) if @options[:raw]
|
86
79
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
object_dump.class.column_names.each_with_object(::ActiveSupport::OrderedHash.new) do |name, hash|
|
92
|
-
if object_dump.has_attribute?(name) || object_dump.new_record?
|
93
|
-
value = object_dump.respond_to?(name) ? object_dump.send(name) : object_dump.read_attribute(name)
|
94
|
-
hash[name.to_sym] = value
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
80
|
+
data = object.instance_variable_get('@base')
|
81
|
+
.attributes
|
82
|
+
.merge(details: object.details.to_h,
|
83
|
+
messages: object.messages.to_h.transform_values(&:to_a))
|
98
84
|
|
99
|
-
|
100
|
-
"#{object} " << awesome_hash(data)
|
85
|
+
[awesome_simple(object.to_s, :active_model_error), awesome_hash(data)].join(' ')
|
101
86
|
end
|
102
87
|
end
|
103
88
|
end
|
@@ -42,6 +42,4 @@ AmazingPrint::Formatter.include AmazingPrint::ActiveSupport
|
|
42
42
|
#
|
43
43
|
# Colorize Rails logs.
|
44
44
|
#
|
45
|
-
if defined?(ActiveSupport::LogSubscriber)
|
46
|
-
AmazingPrint.force_colors! ActiveSupport::LogSubscriber.colorize_logging
|
47
|
-
end
|
45
|
+
AmazingPrint.force_colors! colors: ActiveSupport::LogSubscriber.colorize_logging if defined?(ActiveSupport::LogSubscriber)
|
@@ -19,7 +19,8 @@ module AmazingPrint
|
|
19
19
|
cast = cast_without_mongo_mapper(object, type)
|
20
20
|
|
21
21
|
if defined?(::MongoMapper::Document)
|
22
|
-
if object.is_a?(Class) && !(object.ancestors & [::MongoMapper::Document,
|
22
|
+
if object.is_a?(Class) && !(object.ancestors & [::MongoMapper::Document,
|
23
|
+
::MongoMapper::EmbeddedDocument]).empty?
|
23
24
|
cast = :mongo_mapper_class
|
24
25
|
elsif object.is_a?(::MongoMapper::Document) || object.is_a?(::MongoMapper::EmbeddedDocument)
|
25
26
|
cast = :mongo_mapper_instance
|
@@ -36,9 +37,7 @@ module AmazingPrint
|
|
36
37
|
# Format MongoMapper class object.
|
37
38
|
#------------------------------------------------------------------------------
|
38
39
|
def awesome_mongo_mapper_class(object)
|
39
|
-
if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:keys)
|
40
|
-
return object.inspect
|
41
|
-
end
|
40
|
+
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:keys)
|
42
41
|
|
43
42
|
data = object.keys.sort.each_with_object(::ActiveSupport::OrderedHash.new) do |c, hash|
|
44
43
|
hash[c.first] = (c.last.type || 'undefined').to_s.underscore.intern
|
@@ -86,11 +85,9 @@ module AmazingPrint
|
|
86
85
|
end
|
87
86
|
|
88
87
|
label = object.to_s
|
89
|
-
if object.is_a?(::MongoMapper::EmbeddedDocument)
|
90
|
-
label = "#{colorize('embedded', :assoc)} #{label}"
|
91
|
-
end
|
88
|
+
label = "#{colorize('embedded', :assoc)} #{label}" if object.is_a?(::MongoMapper::EmbeddedDocument)
|
92
89
|
|
93
|
-
|
90
|
+
[label, awesome_hash(data)].join(' ')
|
94
91
|
end
|
95
92
|
|
96
93
|
# Format MongoMapper association object.
|
@@ -31,9 +31,7 @@ module AmazingPrint
|
|
31
31
|
# Format Mongoid class object.
|
32
32
|
#------------------------------------------------------------------------------
|
33
33
|
def awesome_mongoid_class(object)
|
34
|
-
if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:fields)
|
35
|
-
return object.inspect
|
36
|
-
end
|
34
|
+
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:fields)
|
37
35
|
|
38
36
|
data = object.fields.sort.each_with_object(::ActiveSupport::OrderedHash.new) do |c, hash|
|
39
37
|
hash[c[1].name.to_sym] = (c[1].type || 'undefined').to_s.underscore.intern
|
@@ -53,9 +51,7 @@ module AmazingPrint
|
|
53
51
|
data = (object.attributes || {}).sort.each_with_object(::ActiveSupport::OrderedHash.new) do |c, hash|
|
54
52
|
hash[c[0].to_sym] = c[1]
|
55
53
|
end
|
56
|
-
unless object.errors.empty?
|
57
|
-
data = { errors: object.errors, attributes: data }
|
58
|
-
end
|
54
|
+
data = { errors: object.errors, attributes: data } unless object.errors.empty?
|
59
55
|
"#{object} #{awesome_hash(data)}"
|
60
56
|
end
|
61
57
|
|