amazing_print 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +0 -6
- data/CHANGELOG.md +18 -0
- data/Gemfile.lock +34 -36
- data/README.md +8 -5
- 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 +1 -3
- data/lib/amazing_print/core_ext/object.rb +1 -1
- data/lib/amazing_print/custom_defaults.rb +10 -3
- data/lib/amazing_print/ext/active_record.rb +5 -9
- data/lib/amazing_print/ext/active_support.rb +1 -3
- data/lib/amazing_print/ext/mongo_mapper.rb +4 -7
- data/lib/amazing_print/ext/mongoid.rb +2 -6
- data/lib/amazing_print/ext/nobrainer.rb +3 -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 +3 -2
- 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 +3 -0
- data/spec/colors_spec.rb +6 -2
- data/spec/core_ext/logger_spec.rb +7 -7
- data/spec/core_ext/string_spec.rb +2 -2
- data/spec/ext/action_controller_spec.rb +2 -2
- data/spec/ext/active_model_spec.rb +1 -1
- data/spec/ext/active_record_spec.rb +23 -23
- data/spec/ext/active_support_spec.rb +3 -3
- data/spec/ext/mongo_mapper_spec.rb +15 -11
- 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
- metadata +19 -5
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,12 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
if RUBY_VERSION < '3'
|
4
|
-
appraise 'rails-5.1' do
|
5
|
-
gem 'activerecord-jdbcsqlite3-adapter', '~> 51.0', platform: :jruby
|
6
|
-
gem 'rails', '~> 5.1.0'
|
7
|
-
gem 'sqlite3', platform: :mri
|
8
|
-
end
|
9
|
-
|
10
4
|
appraise 'rails-5.2' do
|
11
5
|
gem 'activerecord-jdbcsqlite3-adapter', '~> 52.0', platform: :jruby
|
12
6
|
gem 'rails', '~> 5.2.0'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
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
|
+
|
1
19
|
## v1.2.2
|
2
20
|
- Support Ruby 3.0 / IRB 1.2.6 - #57
|
3
21
|
- Fix FrozenError - #51
|
data/Gemfile.lock
CHANGED
@@ -1,69 +1,66 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
amazing_print (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.
|
13
|
+
ast (2.4.2)
|
14
14
|
coderay (1.1.3)
|
15
15
|
diff-lcs (1.4.4)
|
16
|
-
fakefs (1.
|
17
|
-
ffi (1.13.1-java)
|
18
|
-
jaro_winkler (1.5.4)
|
19
|
-
jaro_winkler (1.5.4-java)
|
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 (
|
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)
|
27
24
|
ast (~> 2.4.1)
|
28
|
-
pry (0.
|
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
|
-
|
30
|
+
rake (13.0.6)
|
31
|
+
regexp_parser (2.1.1)
|
32
|
+
rexml (3.2.5)
|
38
33
|
rspec (3.10.0)
|
39
34
|
rspec-core (~> 3.10.0)
|
40
35
|
rspec-expectations (~> 3.10.0)
|
41
36
|
rspec-mocks (~> 3.10.0)
|
42
|
-
rspec-core (3.10.
|
37
|
+
rspec-core (3.10.1)
|
43
38
|
rspec-support (~> 3.10.0)
|
44
|
-
rspec-expectations (3.10.
|
39
|
+
rspec-expectations (3.10.1)
|
45
40
|
diff-lcs (>= 1.2.0, < 2.0)
|
46
41
|
rspec-support (~> 3.10.0)
|
47
|
-
rspec-mocks (3.10.
|
42
|
+
rspec-mocks (3.10.2)
|
48
43
|
diff-lcs (>= 1.2.0, < 2.0)
|
49
44
|
rspec-support (~> 3.10.0)
|
50
|
-
rspec-support (3.10.
|
51
|
-
rubocop (
|
52
|
-
jaro_winkler (~> 1.5.1)
|
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
|
@@ -73,7 +70,8 @@ DEPENDENCIES
|
|
73
70
|
nokogiri (~> 1.10)
|
74
71
|
pry
|
75
72
|
rspec (~> 3.9)
|
76
|
-
rubocop (~>
|
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
@@ -15,8 +15,8 @@ AmazingPrint is a fork of [AwesomePrint](https://github.com/awesome-print/awesom
|
|
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
|
@@ -325,12 +325,13 @@ red text # (it's red)
|
|
325
325
|
```
|
326
326
|
|
327
327
|
### Setting Custom Defaults ###
|
328
|
-
You can set your own default options by creating
|
329
|
-
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``.
|
330
331
|
For example:
|
331
332
|
|
332
333
|
```ruby
|
333
|
-
# ~/.aprc file.
|
334
|
+
# ~/.config/aprc file.
|
334
335
|
AmazingPrint.defaults = {
|
335
336
|
:indent => -2,
|
336
337
|
:color => {
|
@@ -340,6 +341,8 @@ AmazingPrint.defaults = {
|
|
340
341
|
}
|
341
342
|
```
|
342
343
|
|
344
|
+
The previous `~/.aprc` location is still supported as fallback.
|
345
|
+
|
343
346
|
## Versioning
|
344
347
|
|
345
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.
|
@@ -25,6 +25,4 @@ module AmazingPrint
|
|
25
25
|
end
|
26
26
|
|
27
27
|
Logger.include AmazingPrint::Logger
|
28
|
-
if defined?(ActiveSupport::BufferedLogger)
|
29
|
-
ActiveSupport::BufferedLogger.include AmazingPrint::Logger
|
30
|
-
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(_omit = false)
|
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,15 +45,15 @@ 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
|
@@ -61,12 +61,8 @@ module AmazingPrint
|
|
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
|
@@ -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,9 +85,7 @@ 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
|
@@ -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
|
|
@@ -32,9 +32,9 @@ module AmazingPrint
|
|
32
32
|
#------------------------------------------------------------------------------
|
33
33
|
def awesome_nobrainer_class(object)
|
34
34
|
name = "#{awesome_simple(object, :class)} < #{awesome_simple(object.superclass, :class)}"
|
35
|
-
data =
|
35
|
+
data = object.fields.map do |field, options|
|
36
36
|
[field, (options[:type] || Object).to_s.underscore.to_sym]
|
37
|
-
end
|
37
|
+
end.to_h
|
38
38
|
|
39
39
|
name = "class #{awesome_simple(object.to_s, :class)}"
|
40
40
|
base = "< #{awesome_simple(object.superclass.to_s, :class)}"
|
@@ -46,9 +46,7 @@ module AmazingPrint
|
|
46
46
|
#------------------------------------------------------------------------------
|
47
47
|
def awesome_nobrainer_document(object)
|
48
48
|
data = object.inspectable_attributes.symbolize_keys
|
49
|
-
if object.errors.present?
|
50
|
-
data = { errors: object.errors, attributes: data }
|
51
|
-
end
|
49
|
+
data = { errors: object.errors, attributes: data } if object.errors.present?
|
52
50
|
"#{object} #{awesome_hash(data)}"
|
53
51
|
end
|
54
52
|
end
|
@@ -34,9 +34,7 @@ module AmazingPrint
|
|
34
34
|
xml.gsub!(%r{(<)(/?[A-Za-z1-9]+)}) { |_tag| "#{Regexp.last_match(1)}#{colorize(Regexp.last_match(2), :keyword)}" }
|
35
35
|
xml.gsub!(/(id|class)="[^"]+"/i) { |id| colorize(id, :class) }
|
36
36
|
xml.gsub!(/>([^<]+)</) do |contents|
|
37
|
-
if contents && !contents.empty?
|
38
|
-
contents = colorize(Regexp.last_match(1), :trueclass)
|
39
|
-
end
|
37
|
+
contents = colorize(Regexp.last_match(1), :trueclass) if contents && !contents.empty?
|
40
38
|
">#{contents}<"
|
41
39
|
end
|
42
40
|
xml
|
@@ -14,9 +14,7 @@ module AmazingPrint
|
|
14
14
|
|
15
15
|
def cast_with_ostruct(object, type)
|
16
16
|
cast = cast_without_ostruct(object, type)
|
17
|
-
if defined?(::OpenStruct) && object.is_a?(::OpenStruct)
|
18
|
-
cast = :open_struct_instance
|
19
|
-
end
|
17
|
+
cast = :open_struct_instance if defined?(::OpenStruct) && object.is_a?(::OpenStruct)
|
20
18
|
cast
|
21
19
|
end
|
22
20
|
|
@@ -18,9 +18,10 @@ module AmazingPrint
|
|
18
18
|
cast = cast_without_ripple(object, type)
|
19
19
|
return cast unless defined?(::Ripple)
|
20
20
|
|
21
|
-
|
21
|
+
case object
|
22
|
+
when ::Ripple::AttributeMethods # Module used to access attributes across documents and embedded documents
|
22
23
|
cast = :ripple_document_instance
|
23
|
-
|
24
|
+
when ::Ripple::Properties # Used to access property metadata on Ripple classes
|
24
25
|
cast = :ripple_document_class
|
25
26
|
end
|
26
27
|
cast
|
@@ -58,9 +59,7 @@ module AmazingPrint
|
|
58
59
|
# Format Ripple class object.
|
59
60
|
#------------------------------------------------------------------------------
|
60
61
|
def awesome_ripple_document_class(object)
|
61
|
-
if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:properties)
|
62
|
-
return object.inspect
|
63
|
-
end
|
62
|
+
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:properties)
|
64
63
|
|
65
64
|
name = "class #{awesome_simple(object.to_s, :class)}"
|
66
65
|
base = "< #{awesome_simple(object.superclass.to_s, :class)}"
|
@@ -24,12 +24,11 @@ module AmazingPrint
|
|
24
24
|
#------------------------------------------------------------------------------
|
25
25
|
def format(object, type = nil)
|
26
26
|
core_class = cast(object, type)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
awesome
|
27
|
+
if core_class == :self
|
28
|
+
awesome_self(object, type) # Catch all that falls back to object.inspect.
|
29
|
+
else
|
30
|
+
send(:"awesome_#{core_class}", object) # Core formatters.
|
31
|
+
end
|
33
32
|
end
|
34
33
|
|
35
34
|
# Hook this when adding custom formatters. Check out lib/amazing_print/ext
|
@@ -8,6 +8,7 @@ module AmazingPrint
|
|
8
8
|
attr_reader :array, :inspector, :options
|
9
9
|
|
10
10
|
def initialize(array, inspector)
|
11
|
+
super()
|
11
12
|
@array = array
|
12
13
|
@inspector = inspector
|
13
14
|
@options = inspector.options
|
@@ -33,7 +34,7 @@ module AmazingPrint
|
|
33
34
|
if options[:multiline]
|
34
35
|
multiline_array
|
35
36
|
else
|
36
|
-
|
37
|
+
"[ #{array.map { |item| inspector.awesome(item) }.join(', ')} ]"
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
@@ -114,14 +115,14 @@ module AmazingPrint
|
|
114
115
|
|
115
116
|
meth = begin
|
116
117
|
object.method(name)
|
117
|
-
|
118
|
-
|
118
|
+
rescue NameError, ArgumentError
|
119
|
+
nil
|
119
120
|
end
|
120
121
|
|
121
122
|
meth || begin
|
122
123
|
object.instance_method(name)
|
123
|
-
|
124
|
-
|
124
|
+
rescue NameError
|
125
|
+
nil
|
125
126
|
end
|
126
127
|
end
|
127
128
|
|
@@ -30,7 +30,7 @@ module AmazingPrint
|
|
30
30
|
# ]
|
31
31
|
#------------------------------------------------------------------------------
|
32
32
|
def should_be_limited?
|
33
|
-
options[:limit] || (options[:limit].is_a?(Integer) &&
|
33
|
+
options[:limit] || (options[:limit].is_a?(Integer) && options[:limit].positive?)
|
34
34
|
end
|
35
35
|
|
36
36
|
def get_limit_size
|
@@ -42,14 +42,14 @@ module AmazingPrint
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
def limited(data, width, is_hash
|
45
|
+
def limited(data, width, is_hash: false)
|
46
46
|
limit = get_limit_size
|
47
47
|
if data.length <= limit
|
48
48
|
data
|
49
49
|
else
|
50
50
|
# Calculate how many elements to be displayed above and below the separator.
|
51
51
|
head = limit / 2
|
52
|
-
tail = head - (limit - 1) % 2
|
52
|
+
tail = head - ((limit - 1) % 2)
|
53
53
|
|
54
54
|
# Add the proper elements to the temp array and format the separator.
|
55
55
|
temp = data[0, head] + [nil] + data[-tail, tail]
|
@@ -65,23 +65,18 @@ module AmazingPrint
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def method_tuple(method)
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|
82
|
-
else # See http://ruby-doc.org/core/classes/Method.html#M001902
|
83
|
-
args = (1..method.arity.abs).map { |i| "arg#{i}" }
|
84
|
-
args[-1] = "*#{args[-1]}" if method.arity < 0
|
68
|
+
# See http://readruby.chengguangnan.com/methods#method-objects-parameters
|
69
|
+
# (mirror: http://archive.is/XguCA#selection-3381.1-3381.11)
|
70
|
+
args = method.parameters.inject([]) do |arr, (type, name)|
|
71
|
+
name ||= (type == :block ? 'block' : "arg#{arr.size + 1}")
|
72
|
+
arr << case type
|
73
|
+
when :req then name.to_s
|
74
|
+
when :keyreq then "#{name}:"
|
75
|
+
when :key then "*#{name}:"
|
76
|
+
when :opt, :rest then "*#{name}"
|
77
|
+
when :block then "&#{name}"
|
78
|
+
else '?'
|
79
|
+
end
|
85
80
|
end
|
86
81
|
|
87
82
|
# method.to_s formats to handle:
|
@@ -95,7 +90,7 @@ module AmazingPrint
|
|
95
90
|
# #<UnboundMethod: Hello#world>
|
96
91
|
# #<UnboundMethod: Hello#world() /home/hs/code/amazing_print/spec/methods_spec.rb:68>
|
97
92
|
#
|
98
|
-
if method.to_s =~ %r{(Unbound)*Method: ((#<)?[^/#]*)[
|
93
|
+
if method.to_s =~ %r{(Unbound)*Method: ((#<)?[^/#]*)[#.]}
|
99
94
|
unbound = Regexp.last_match(1) && '(unbound)'
|
100
95
|
klass = Regexp.last_match(2)
|
101
96
|
if klass && klass =~ /(\(\w+:\s.*?\))/ # Is this ActiveRecord-style class?
|
@@ -123,21 +118,21 @@ module AmazingPrint
|
|
123
118
|
INDENT_CACHE = (0..100).map { |i| ' ' * i }.map(&:freeze).freeze
|
124
119
|
|
125
120
|
def indent(n = indentation)
|
126
|
-
INDENT_CACHE[n] || ' ' * n
|
121
|
+
INDENT_CACHE[n] || (' ' * n)
|
127
122
|
end
|
128
123
|
|
129
124
|
def outdent
|
130
125
|
i = indentation - options[:indent].abs
|
131
126
|
|
132
|
-
INDENT_CACHE[i] || ' ' * i
|
127
|
+
INDENT_CACHE[i] || (' ' * i)
|
133
128
|
end
|
134
129
|
|
135
130
|
def align(value, width)
|
136
131
|
if options[:multiline]
|
137
132
|
indent_option = options[:indent]
|
138
|
-
if indent_option
|
133
|
+
if indent_option.positive?
|
139
134
|
value.rjust(width)
|
140
|
-
elsif indent_option
|
135
|
+
elsif indent_option.zero?
|
141
136
|
"#{indent}#{value.ljust(width)}"
|
142
137
|
else
|
143
138
|
"#{indent(indentation + indent_option)}#{value.ljust(width)}"
|