awesome_print 1.8.0 → 2.0.0.pre
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/.gitignore +1 -0
- data/Appraisals +16 -48
- data/CHANGELOG.md +10 -1
- data/LICENSE +16 -19
- data/README.md +3 -10
- data/lib/ap.rb +1 -5
- data/lib/awesome_print.rb +7 -29
- data/lib/awesome_print/colorize.rb +2 -0
- data/lib/awesome_print/core_ext/active_support.rb +7 -0
- data/lib/awesome_print/core_ext/awesome_method_array.rb +0 -6
- data/lib/awesome_print/core_ext/class.rb +0 -5
- data/lib/awesome_print/core_ext/kernel.rb +0 -5
- data/lib/awesome_print/core_ext/logger.rb +0 -5
- data/lib/awesome_print/core_ext/object.rb +0 -5
- data/lib/awesome_print/core_ext/string.rb +0 -5
- data/lib/awesome_print/formatter.rb +38 -98
- data/lib/awesome_print/formatters/array_formatter.rb +10 -7
- data/lib/awesome_print/formatters/base_formatter.rb +17 -50
- data/lib/awesome_print/formatters/bigdecimal_formatter.rb +20 -0
- data/lib/awesome_print/formatters/class_formatter.rb +5 -6
- data/lib/awesome_print/formatters/dir_formatter.rb +4 -6
- data/lib/awesome_print/formatters/ext/active_model_error_formatter.rb +44 -0
- data/lib/awesome_print/formatters/ext/active_record_attributeset_formatter.rb +27 -0
- data/lib/awesome_print/formatters/ext/active_record_class_formatter.rb +43 -0
- data/lib/awesome_print/formatters/ext/active_record_instance_formatter.rb +48 -0
- data/lib/awesome_print/formatters/ext/active_record_relation_formatter.rb +19 -0
- data/lib/awesome_print/formatters/ext/bson_objectid_formatter.rb +20 -0
- data/lib/awesome_print/formatters/ext/hash_with_indifferent_access_formatter.rb +20 -0
- data/lib/awesome_print/formatters/ext/mongoid_document_formatter.rb +59 -0
- data/lib/awesome_print/formatters/ext/nokogiri_document_formatter.rb +30 -0
- data/lib/awesome_print/formatters/ext/nokogiri_node_formatter.rb +29 -0
- data/lib/awesome_print/formatters/ext/nokogiri_nodeset_formatter.rb +32 -0
- data/lib/awesome_print/formatters/ext/sequel_dataset_formatter.rb +20 -0
- data/lib/awesome_print/formatters/ext/sequel_model_class_formatter.rb +25 -0
- data/lib/awesome_print/formatters/ext/sequel_model_formatter.rb +26 -0
- data/lib/awesome_print/formatters/ext/time_with_zone_formatter.rb +24 -0
- data/lib/awesome_print/formatters/fallback_formatter.rb +55 -0
- data/lib/awesome_print/formatters/false_class_formatter.rb +15 -0
- data/lib/awesome_print/formatters/file_formatter.rb +4 -6
- data/lib/awesome_print/formatters/hash_formatter.rb +12 -7
- data/lib/awesome_print/formatters/integer_formatter.rb +11 -0
- data/lib/awesome_print/formatters/method_formatter.rb +8 -6
- data/lib/awesome_print/formatters/module_formatter.rb +18 -0
- data/lib/awesome_print/formatters/nil_class_formatter.rb +19 -0
- data/lib/awesome_print/formatters/object_formatter.rb +20 -7
- data/lib/awesome_print/formatters/open_struct.rb +19 -0
- data/lib/awesome_print/formatters/range_formatter.rb +11 -0
- data/lib/awesome_print/formatters/rational_formatter.rb +15 -0
- data/lib/awesome_print/formatters/set_formatter.rb +19 -0
- data/lib/awesome_print/formatters/simple_formatter.rb +10 -8
- data/lib/awesome_print/formatters/string_formatter.rb +14 -0
- data/lib/awesome_print/formatters/struct_formatter.rb +8 -6
- data/lib/awesome_print/formatters/symbol_formatter.rb +18 -0
- data/lib/awesome_print/formatters/true_class_formatter.rb +15 -0
- data/lib/awesome_print/formatters/unbound_method_formatter.rb +15 -0
- data/lib/awesome_print/inspector.rb +20 -16
- data/lib/awesome_print/limiter.rb +63 -0
- data/lib/awesome_print/registrar.rb +20 -0
- data/lib/awesome_print/version.rb +6 -6
- data/spec/formatters/array_spec.rb +251 -0
- data/spec/formatters/big_decimal_spec.rb +28 -0
- data/spec/formatters/class_spec.rb +91 -0
- data/spec/formatters/dir_file_spec.rb +43 -0
- data/spec/{ext → formatters/ext}/active_record_spec.rb +27 -63
- data/spec/{ext → formatters/ext}/active_support_spec.rb +6 -6
- data/spec/{ext → formatters/ext}/mongoid_spec.rb +4 -41
- data/spec/{ext → formatters/ext}/nokogiri_spec.rb +0 -0
- data/spec/formatters/hash_spec.rb +284 -0
- data/spec/{methods_spec.rb → formatters/methods_spec.rb} +13 -7
- data/spec/{objects_spec.rb → formatters/objects_spec.rb} +49 -0
- data/spec/{ext → formatters}/ostruct_spec.rb +1 -0
- data/spec/formatters/set_spec.rb +49 -0
- data/spec/formatters/struct_spec.rb +61 -0
- data/spec/merge_options_spec.rb +13 -0
- data/spec/misc_spec.rb +21 -21
- data/spec/spec_helper.rb +5 -10
- data/spec/support/active_record_data/5_1_diana.txt +104 -0
- data/spec/support/active_record_data/5_1_multi.txt +210 -0
- data/spec/support/active_record_data/5_2_diana.txt +104 -0
- data/spec/support/active_record_data/5_2_multi.txt +210 -0
- data/spec/support/ext_verifier.rb +0 -15
- data/spec/support/mongoid_versions.rb +4 -4
- data/spec/support/rails_versions.rb +10 -20
- metadata +98 -87
- data/lib/awesome_print/core_ext/method.rb +0 -21
- data/lib/awesome_print/ext/action_view.rb +0 -22
- data/lib/awesome_print/ext/active_record.rb +0 -78
- data/lib/awesome_print/ext/active_support.rb +0 -47
- data/lib/awesome_print/ext/mongo_mapper.rb +0 -124
- data/lib/awesome_print/ext/mongoid.rb +0 -67
- data/lib/awesome_print/ext/nobrainer.rb +0 -52
- data/lib/awesome_print/ext/nokogiri.rb +0 -45
- data/lib/awesome_print/ext/ostruct.rb +0 -27
- data/lib/awesome_print/ext/ripple.rb +0 -71
- data/lib/awesome_print/ext/sequel.rb +0 -58
- data/spec/ext/action_view_spec.rb +0 -18
- data/spec/ext/mongo_mapper_spec.rb +0 -261
- data/spec/ext/nobrainer_spec.rb +0 -59
- data/spec/ext/ripple_spec.rb +0 -48
- data/spec/formats_spec.rb +0 -779
- data/spec/support/active_record_data/3_2_diana.txt +0 -24
- data/spec/support/active_record_data/3_2_diana_legacy.txt +0 -24
- data/spec/support/active_record_data/3_2_multi.txt +0 -50
- data/spec/support/active_record_data/3_2_multi_legacy.txt +0 -50
- data/spec/support/active_record_data/4_0_diana.txt +0 -98
- data/spec/support/active_record_data/4_0_multi.txt +0 -198
- data/spec/support/active_record_data/4_1_diana.txt +0 -97
- data/spec/support/active_record_data/4_1_multi.txt +0 -196
- data/spec/support/active_record_data/4_2_diana.txt +0 -109
- data/spec/support/active_record_data/4_2_diana_legacy.txt +0 -109
- data/spec/support/active_record_data/4_2_multi.txt +0 -220
- data/spec/support/active_record_data/4_2_multi_legacy.txt +0 -220
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b78e2becdd2b08753b1e78e1c2c46e531f6750a2
|
|
4
|
+
data.tar.gz: 9e79ebd10b6b47e9026d0e412f83615466e67c89
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2b6b91f195831126213e10ffba034c1ed5f6be030b5bc89870aeead7c6edb95a39a3968d24c60f06c4d2c88e16b4c7f7974ee0b81e3b33c66de5e36ce916e4e9
|
|
7
|
+
data.tar.gz: 4bb762cc93185b014c5f56b8a4b1cccaa2a52277b88efe68c8cc4c85728db7fd9a7e6fd5c1f63677e865a34aa671c03a2239df5a6d91eb4fffb4dc83cb54703e
|
data/.gitignore
CHANGED
data/Appraisals
CHANGED
|
@@ -1,63 +1,31 @@
|
|
|
1
|
-
appraise 'rails-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
# The last version that doesn't need Ruby 2.0 and works with version 4.0 of
|
|
10
|
-
# Rails. This addresses a build problem with Travis for version 1.9.3 of Ruby
|
|
11
|
-
gem 'mime-types', '2.6.2', :platforms => :ruby_19
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
appraise 'rails-4.1' do
|
|
15
|
-
gem 'rails', '~> 4.1.0'
|
|
16
|
-
|
|
17
|
-
# The last version that doesn't need Ruby 2.0 and works with version 4.1 of
|
|
18
|
-
# Rails. This addresses a build problem with Travis for version 1.9.3 of Ruby
|
|
19
|
-
gem 'mime-types', '2.6.2', :platforms => :ruby_19
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
appraise 'rails-4.2' do
|
|
23
|
-
gem 'rails', '~> 4.2.0'
|
|
24
|
-
|
|
25
|
-
# The last version that doesn't need Ruby 2.0 and works with version 4.2 of
|
|
26
|
-
# Rails. This addresses a build problem with Travis for version 1.9.3 of Ruby
|
|
27
|
-
gem 'mime-types', '2.6.2', :platforms => :ruby_19
|
|
28
|
-
end
|
|
1
|
+
# appraise 'rails-4.2' do
|
|
2
|
+
# gem 'rails', '~> 4.2.0'
|
|
3
|
+
#
|
|
4
|
+
# # The last version that doesn't need Ruby 2.0 and works with version 4.2 of
|
|
5
|
+
# # Rails. This addresses a build problem with Travis for version 1.9.3 of Ruby
|
|
6
|
+
# gem 'mime-types', '2.6.2', :platforms => :ruby_19
|
|
7
|
+
# end
|
|
29
8
|
|
|
30
9
|
appraise 'rails-5.0' do
|
|
31
|
-
|
|
32
|
-
gem 'rails', '>= 5.0.0.racecar1', '< 5.1'
|
|
10
|
+
gem 'rails', '>= 5.0.0', '< 5.1'
|
|
33
11
|
end
|
|
34
12
|
|
|
35
|
-
appraise '
|
|
36
|
-
gem '
|
|
13
|
+
appraise 'rails-5.1' do
|
|
14
|
+
gem 'rails', '>= 5.1.0', '< 5.2'
|
|
37
15
|
end
|
|
38
16
|
|
|
39
|
-
appraise '
|
|
40
|
-
gem '
|
|
41
|
-
gem 'json', '~> 1.8', :platforms => :ruby_19 # Json 2.0 requires Ruby >= 2.0
|
|
17
|
+
appraise 'rails-5.2' do
|
|
18
|
+
gem 'rails', '>= 5.2.0', '< 5.3'
|
|
42
19
|
end
|
|
43
20
|
|
|
44
21
|
appraise 'mongoid-4.0' do
|
|
45
22
|
gem 'mongoid', '~> 4.0.0'
|
|
46
23
|
end
|
|
47
24
|
|
|
48
|
-
appraise '
|
|
49
|
-
gem '
|
|
25
|
+
appraise 'mongoid-5.0' do
|
|
26
|
+
gem 'mongoid', '~> 5.0.0'
|
|
50
27
|
end
|
|
51
28
|
|
|
52
|
-
appraise '
|
|
53
|
-
gem '
|
|
54
|
-
gem 'ripple'
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
appraise 'nobrainer' do
|
|
58
|
-
gem 'nobrainer'
|
|
59
|
-
|
|
60
|
-
# When activesupport 5 was released, it required ruby 2.2.2 as a minimum.
|
|
61
|
-
# Locking this down to 4.2.6 allows our Ruby 1.9 tests to keep working.
|
|
62
|
-
gem 'activesupport', '4.2.6', :platforms => :ruby_19
|
|
29
|
+
appraise 'mongoid-6.0' do
|
|
30
|
+
gem 'mongoid', '~> 6.0.0'
|
|
63
31
|
end
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
## master (unreleased)
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
## 2.0.0-pre
|
|
4
|
+
- Massive overhaul in the way formatters work. Now they are registered with a factory pattern, which includes
|
|
5
|
+
a simple method to determine if that formatter can handle the content. [@imajes]
|
|
6
|
+
- Remove support for mongo mapper, and ruby pre 2.x [@imajes]
|
|
7
|
+
- It's probably faster? :)
|
|
8
|
+
- Fixes spec suite to properly work via travis, gets a clean build [@imajes, others]
|
|
9
|
+
- Adds support for ActiveModel::Errors [@dshinzie] - [#301]
|
|
10
|
+
- removes use of `strip_heredoc` from specs as it's a rails dep [@kstephens] - [#303]
|
|
11
|
+
- ArrayFormatter now returns arrays for has_many :through associations [@chadh13] - [#332]
|
|
3
12
|
|
|
4
13
|
## 1.8.0
|
|
5
14
|
- stat("$HOME/.aprc") once [@kstephens] - [#304]
|
data/LICENSE
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
Copyright (c) 2010-
|
|
2
|
-
http://www.dvorkin.net
|
|
3
|
-
%w(mike dvorkin.net) * "@" || "twitter.com/mid"
|
|
1
|
+
Copyright (c) 2010-2019 Michael Dvorkin
|
|
4
2
|
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
the following conditions:
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
12
9
|
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
|
14
|
-
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
15
12
|
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
OF
|
|
22
|
-
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
data/README.md
CHANGED
|
@@ -43,6 +43,8 @@ sort_keys: false, # Do not sort hash keys.
|
|
|
43
43
|
sort_vars: true, # Sort instance variables.
|
|
44
44
|
limit: false, # Limit arrays & hashes. Accepts bool or int.
|
|
45
45
|
ruby19_syntax: false, # Use Ruby 1.9 hash syntax in output.
|
|
46
|
+
class_name: :class, # Method called to report the instance class name. (e.g. :to_s)
|
|
47
|
+
object_id: true, # Show object id.
|
|
46
48
|
color: {
|
|
47
49
|
args: :pale,
|
|
48
50
|
array: :white,
|
|
@@ -50,7 +52,7 @@ color: {
|
|
|
50
52
|
class: :yellow,
|
|
51
53
|
date: :greenish,
|
|
52
54
|
falseclass: :red,
|
|
53
|
-
|
|
55
|
+
integer: :blue,
|
|
54
56
|
float: :blue,
|
|
55
57
|
hash: :pale,
|
|
56
58
|
keyword: :cyan,
|
|
@@ -331,20 +333,11 @@ AwesomePrint.defaults = {
|
|
|
331
333
|
```
|
|
332
334
|
|
|
333
335
|
## Versioning
|
|
334
|
-
|
|
335
336
|
AwesomePrint follows the [Semantic Versioning](http://semver.org/) standard.
|
|
336
337
|
|
|
337
338
|
### Contributing ###
|
|
338
339
|
See [CONTRIBUTING.md](CONTRIBUTING.md) for information.
|
|
339
340
|
|
|
340
|
-
### License ###
|
|
341
|
-
Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
|
342
|
-
|
|
343
|
-
http://www.dvorkin.net
|
|
344
|
-
|
|
345
|
-
%w(mike dvorkin.net) * "@" || "twitter.com/mid"
|
|
346
|
-
|
|
347
|
-
Released under the MIT license. See LICENSE file for details.
|
|
348
341
|
|
|
349
342
|
[gem_version_badge]: https://img.shields.io/gem/v/awesome_print.svg?style=flat
|
|
350
343
|
[gem_downloads_badge]: http://img.shields.io/gem/dt/awesome_print.svg?style=flat
|
data/lib/ap.rb
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
|
2
|
-
#
|
|
3
|
-
# Awesome Print is freely distributable under the terms of MIT license.
|
|
4
|
-
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
|
5
|
-
#------------------------------------------------------------------------------
|
|
6
1
|
#
|
|
7
2
|
# Keeping this for backwards compatibility to allow
|
|
8
3
|
# require "ap"
|
|
9
4
|
#
|
|
10
5
|
require File.dirname(__FILE__) + '/awesome_print'
|
|
6
|
+
|
data/lib/awesome_print.rb
CHANGED
|
@@ -1,41 +1,19 @@
|
|
|
1
|
-
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
|
2
|
-
#
|
|
3
|
-
# Awesome Print is freely distributable under the terms of MIT license.
|
|
4
|
-
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
|
5
|
-
#------------------------------------------------------------------------------
|
|
6
|
-
#
|
|
7
1
|
# AwesomePrint might be loaded implicitly through ~/.irbrc or ~/.pryrc
|
|
8
2
|
# so do nothing for subsequent requires.
|
|
9
3
|
#
|
|
10
4
|
unless defined?(AwesomePrint::Inspector)
|
|
11
|
-
|
|
5
|
+
# FIXME: not sure we need these, but..
|
|
6
|
+
require 'awesome_print/custom_defaults'
|
|
7
|
+
|
|
8
|
+
%w(active_support awesome_method_array string object class kernel).each do |file|
|
|
12
9
|
require "awesome_print/core_ext/#{file}"
|
|
13
10
|
end
|
|
14
11
|
|
|
15
|
-
require 'awesome_print/custom_defaults'
|
|
16
12
|
require 'awesome_print/inspector'
|
|
17
13
|
require 'awesome_print/formatter'
|
|
14
|
+
|
|
15
|
+
Dir["./lib/awesome_print/formatters/**/*.rb"].each { |f| require f }
|
|
16
|
+
|
|
18
17
|
require 'awesome_print/version'
|
|
19
18
|
require 'awesome_print/core_ext/logger' if defined?(Logger)
|
|
20
|
-
#
|
|
21
|
-
# Load the following under normal circumstances as well as in Rails
|
|
22
|
-
# console when required from ~/.irbrc or ~/.pryrc.
|
|
23
|
-
#
|
|
24
|
-
require 'awesome_print/ext/active_record' if defined?(ActiveRecord) || AwesomePrint.rails_console?
|
|
25
|
-
require 'awesome_print/ext/active_support' if defined?(ActiveSupport) || AwesomePrint.rails_console?
|
|
26
|
-
#
|
|
27
|
-
# Load remaining extensions.
|
|
28
|
-
#
|
|
29
|
-
if defined?(ActiveSupport.on_load)
|
|
30
|
-
ActiveSupport.on_load(:action_view) do
|
|
31
|
-
require 'awesome_print/ext/action_view'
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
require 'awesome_print/ext/mongo_mapper' if defined?(MongoMapper)
|
|
35
|
-
require 'awesome_print/ext/mongoid' if defined?(Mongoid)
|
|
36
|
-
require 'awesome_print/ext/nokogiri' if defined?(Nokogiri)
|
|
37
|
-
require 'awesome_print/ext/nobrainer' if defined?(NoBrainer)
|
|
38
|
-
require 'awesome_print/ext/ripple' if defined?(Ripple)
|
|
39
|
-
require 'awesome_print/ext/sequel' if defined?(Sequel)
|
|
40
|
-
require 'awesome_print/ext/ostruct' if defined?(OpenStruct)
|
|
41
19
|
end
|
|
@@ -6,6 +6,8 @@ module AwesomePrint
|
|
|
6
6
|
# Pick the color and apply it to the given string as necessary.
|
|
7
7
|
#------------------------------------------------------------------------------
|
|
8
8
|
def colorize(str, type)
|
|
9
|
+
# puts "[COLORIZING] - using #{options[:color][type]} for #{type}" if AwesomePrint.debug
|
|
10
|
+
|
|
9
11
|
str = CGI.escapeHTML(str) if options[:html]
|
|
10
12
|
if options[:plain] || !options[:color][type] || !inspector.colorize?
|
|
11
13
|
str
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
|
2
|
-
#
|
|
3
|
-
# Awesome Print is freely distributable under the terms of MIT license.
|
|
4
|
-
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
|
5
|
-
#------------------------------------------------------------------------------
|
|
6
|
-
#
|
|
7
1
|
# The following makes it possible to invoke awesome_print while performing
|
|
8
2
|
# operations on method arrays, ex:
|
|
9
3
|
#
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
|
2
|
-
#
|
|
3
|
-
# Awesome Print is freely distributable under the terms of MIT license.
|
|
4
|
-
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
|
5
|
-
#------------------------------------------------------------------------------
|
|
6
1
|
class Class #:nodoc:
|
|
7
2
|
#
|
|
8
3
|
# Intercept methods below to inject @__awesome_print__ instance variable
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
|
2
|
-
#
|
|
3
|
-
# Awesome Print is freely distributable under the terms of MIT license.
|
|
4
|
-
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
|
5
|
-
#------------------------------------------------------------------------------
|
|
6
1
|
module Kernel
|
|
7
2
|
|
|
8
3
|
def ai(options = {})
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
|
2
|
-
#
|
|
3
|
-
# Awesome Print is freely distributable under the terms of MIT license.
|
|
4
|
-
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
|
5
|
-
#------------------------------------------------------------------------------
|
|
6
1
|
module AwesomePrint
|
|
7
2
|
module Logger
|
|
8
3
|
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
|
2
|
-
#
|
|
3
|
-
# Awesome Print is freely distributable under the terms of MIT license.
|
|
4
|
-
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
|
5
|
-
#------------------------------------------------------------------------------
|
|
6
1
|
class Object #:nodoc:
|
|
7
2
|
#
|
|
8
3
|
# Intercept methods below to inject @__awesome_print__ instance variable
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
|
2
|
-
#
|
|
3
|
-
# Awesome Print is freely distributable under the terms of MIT license.
|
|
4
|
-
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
|
5
|
-
#------------------------------------------------------------------------------
|
|
6
1
|
class String
|
|
7
2
|
#
|
|
8
3
|
# ANSI color codes:
|
|
@@ -1,126 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
#
|
|
3
|
-
# Awesome Print is freely distributable under the terms of MIT license.
|
|
4
|
-
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
|
5
|
-
#------------------------------------------------------------------------------
|
|
6
|
-
require 'awesome_print/formatters'
|
|
1
|
+
require_relative 'colorize'
|
|
7
2
|
|
|
8
3
|
module AwesomePrint
|
|
9
4
|
class Formatter
|
|
5
|
+
|
|
10
6
|
include Colorize
|
|
11
7
|
|
|
12
8
|
attr_reader :inspector, :options
|
|
13
9
|
|
|
14
|
-
|
|
10
|
+
# Acts as a class ivar
|
|
11
|
+
@registered_formatters = {}
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@
|
|
13
|
+
# make it accessible
|
|
14
|
+
def self.registered_formatters
|
|
15
|
+
@registered_formatters
|
|
19
16
|
end
|
|
20
17
|
|
|
21
|
-
#
|
|
18
|
+
# register a new formatter..
|
|
22
19
|
#------------------------------------------------------------------------------
|
|
23
|
-
def
|
|
24
|
-
|
|
25
|
-
awesome = if core_class != :self
|
|
26
|
-
send(:"awesome_#{core_class}", object) # Core formatters.
|
|
27
|
-
else
|
|
28
|
-
awesome_self(object, type) # Catch all that falls back to object.inspect.
|
|
29
|
-
end
|
|
30
|
-
awesome
|
|
20
|
+
def self.register(formatter)
|
|
21
|
+
@registered_formatters[formatter.formatted_object_type.to_sym] = formatter
|
|
31
22
|
end
|
|
32
23
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def cast(object, type)
|
|
37
|
-
CORE.grep(type)[0] || :self
|
|
24
|
+
def initialize(inspector)
|
|
25
|
+
@inspector = inspector
|
|
26
|
+
@options = inspector.options
|
|
38
27
|
end
|
|
39
28
|
|
|
40
|
-
private
|
|
41
29
|
|
|
42
|
-
#
|
|
30
|
+
# Main entry point to format an object.
|
|
31
|
+
# type is determined by Inspector#printable
|
|
43
32
|
#------------------------------------------------------------------------------
|
|
44
|
-
def
|
|
45
|
-
|
|
46
|
-
awesome_object(object)
|
|
47
|
-
elsif (hash = convert_to_hash(object))
|
|
48
|
-
awesome_hash(hash)
|
|
49
|
-
else
|
|
50
|
-
awesome_simple(object.inspect.to_s, type, @inspector)
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def awesome_bigdecimal(n)
|
|
55
|
-
o = n.to_s('F')
|
|
56
|
-
type = :bigdecimal
|
|
57
|
-
awesome_simple(o, type, @inspector)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def awesome_rational(n)
|
|
61
|
-
o = n.to_s
|
|
62
|
-
type = :rational
|
|
63
|
-
awesome_simple(o, type, @inspector)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def awesome_simple(o, type, inspector = @inspector)
|
|
67
|
-
AwesomePrint::Formatters::SimpleFormatter.new(o, type, inspector).format
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def awesome_array(a)
|
|
71
|
-
Formatters::ArrayFormatter.new(a, @inspector).format
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def awesome_set(s)
|
|
75
|
-
Formatters::ArrayFormatter.new(s.to_a, @inspector).format
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def awesome_hash(h)
|
|
79
|
-
Formatters::HashFormatter.new(h, @inspector).format
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def awesome_object(o)
|
|
83
|
-
Formatters::ObjectFormatter.new(o, @inspector).format
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def awesome_struct(s)
|
|
87
|
-
Formatters::StructFormatter.new(s, @inspector).format
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def awesome_method(m)
|
|
91
|
-
Formatters::MethodFormatter.new(m, @inspector).format
|
|
92
|
-
end
|
|
93
|
-
alias :awesome_unboundmethod :awesome_method
|
|
33
|
+
def format(object, type = nil)
|
|
34
|
+
puts "\n\n[FMT] #{type.to_s.red} >>> #{object}" if AwesomePrint.debug
|
|
94
35
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
end
|
|
36
|
+
format_with = active_formatter(type)
|
|
37
|
+
puts "[ACTIVE] using > #{format_with.to_s.blueish} < to format" if format_with && AwesomePrint.debug
|
|
98
38
|
|
|
99
|
-
|
|
100
|
-
Formatters::FileFormatter.new(f, @inspector).format
|
|
101
|
-
end
|
|
39
|
+
# if we have an active formatter, and it's good to go, lets return that
|
|
102
40
|
|
|
103
|
-
|
|
104
|
-
Formatters::DirFormatter.new(d, @inspector).format
|
|
105
|
-
end
|
|
41
|
+
return format_with.new(@inspector).format(object) if format_with&.formattable?(object)
|
|
106
42
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
end
|
|
43
|
+
# if that's not working, lets try discover the format via formattable?
|
|
44
|
+
self.class.registered_formatters.each do |fmt|
|
|
45
|
+
puts "[FIND] trying to use [#{fmt.first.to_s.greenish} - #{fmt.last.to_s.blue}] - core: #{fmt.last.core?}" if AwesomePrint.debug
|
|
46
|
+
#{fmt.last.core?}" if AwesomePrint.debug
|
|
47
|
+
next if fmt.last.core? # if it's a core level formatter, move on
|
|
113
48
|
|
|
114
|
-
|
|
115
|
-
|
|
49
|
+
if fmt.last.formattable?(object)
|
|
50
|
+
puts "[FMT] Jackpot! using #{fmt.first.to_s.red} >>> #{object}" if AwesomePrint.debug
|
|
51
|
+
return fmt.last.new(@inspector).format(object)
|
|
52
|
+
end
|
|
116
53
|
end
|
|
117
54
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
55
|
+
# we've run out of options. lets try and coerce into something we can work
|
|
56
|
+
# with
|
|
57
|
+
puts "[FALLBACK] well darn, we're just gonna have to fb" if AwesomePrint.debug
|
|
58
|
+
AwesomePrint::Formatters::FallbackFormatter.new(@inspector).format(object)
|
|
59
|
+
end
|
|
122
60
|
|
|
123
|
-
|
|
61
|
+
def active_formatter(type)
|
|
62
|
+
self.class.registered_formatters[type]
|
|
124
63
|
end
|
|
125
64
|
end
|
|
126
65
|
end
|
|
66
|
+
|