awesome_print 1.6.1 → 1.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +4 -0
- data/Appraisals +45 -22
- data/{CHANGELOG → CHANGELOG.md} +83 -18
- data/CONTRIBUTING.md +45 -4
- data/Gemfile.lock +28 -22
- data/LICENSE +16 -19
- data/README.md +97 -92
- data/Rakefile +5 -5
- data/awesome_print.gemspec +33 -0
- data/init.rb +1 -0
- data/lib/ap.rb +2 -2
- data/lib/awesome_print/colorize.rb +24 -0
- data/lib/awesome_print/core_ext/{array.rb → awesome_method_array.rb} +16 -18
- data/lib/awesome_print/core_ext/class.rb +3 -2
- data/lib/awesome_print/core_ext/kernel.rb +1 -1
- data/lib/awesome_print/core_ext/logger.rb +1 -1
- data/lib/awesome_print/core_ext/method.rb +2 -2
- data/lib/awesome_print/core_ext/object.rb +3 -2
- data/lib/awesome_print/core_ext/string.rb +3 -3
- data/lib/awesome_print/custom_defaults.rb +57 -0
- data/lib/awesome_print/ext/action_view.rb +8 -4
- data/lib/awesome_print/ext/active_record.rb +45 -12
- data/lib/awesome_print/ext/active_support.rb +1 -1
- data/lib/awesome_print/ext/mongo_mapper.rb +16 -13
- data/lib/awesome_print/ext/mongoid.rb +8 -6
- data/lib/awesome_print/ext/nobrainer.rb +52 -0
- data/lib/awesome_print/ext/nokogiri.rb +4 -4
- data/lib/awesome_print/ext/ostruct.rb +1 -1
- data/lib/awesome_print/ext/ripple.rb +5 -6
- data/lib/awesome_print/ext/sequel.rb +7 -6
- data/lib/awesome_print/formatter.rb +54 -327
- data/lib/awesome_print/formatters/array_formatter.rb +139 -0
- data/lib/awesome_print/formatters/base_formatter.rb +140 -0
- data/lib/awesome_print/formatters/class_formatter.rb +25 -0
- data/lib/awesome_print/formatters/dir_formatter.rb +22 -0
- data/lib/awesome_print/formatters/file_formatter.rb +22 -0
- data/lib/awesome_print/formatters/hash_formatter.rb +106 -0
- data/lib/awesome_print/formatters/method_formatter.rb +22 -0
- data/lib/awesome_print/formatters/object_formatter.rb +78 -0
- data/lib/awesome_print/formatters/simple_formatter.rb +21 -0
- data/lib/awesome_print/formatters/struct_formatter.rb +71 -0
- data/lib/awesome_print/formatters.rb +15 -0
- data/lib/awesome_print/indentator.rb +18 -0
- data/lib/awesome_print/inspector.rb +92 -94
- data/lib/awesome_print/version.rb +2 -2
- data/lib/awesome_print.rb +19 -18
- data/spec/active_record_helper.rb +24 -28
- data/spec/colors_spec.rb +31 -31
- data/spec/core_ext/logger_spec.rb +43 -0
- data/spec/core_ext/string_spec.rb +20 -0
- data/spec/ext/action_view_spec.rb +21 -0
- data/spec/ext/active_record_spec.rb +260 -0
- data/spec/ext/active_support_spec.rb +30 -0
- data/spec/ext/mongo_mapper_spec.rb +261 -0
- data/spec/ext/mongoid_spec.rb +67 -0
- data/spec/ext/nobrainer_spec.rb +59 -0
- data/spec/ext/nokogiri_spec.rb +46 -0
- data/spec/ext/ostruct_spec.rb +22 -0
- data/spec/ext/ripple_spec.rb +48 -0
- data/spec/formats_spec.rb +251 -184
- data/spec/methods_spec.rb +126 -130
- data/spec/misc_spec.rb +98 -93
- data/spec/objects_spec.rb +162 -27
- data/spec/spec_helper.rb +72 -38
- data/spec/support/active_record_data/3_2_diana.txt +24 -0
- data/spec/support/active_record_data/3_2_diana_legacy.txt +24 -0
- data/spec/support/active_record_data/3_2_multi.txt +50 -0
- data/spec/support/active_record_data/3_2_multi_legacy.txt +50 -0
- data/spec/support/active_record_data/4_0_diana.txt +98 -0
- data/spec/support/active_record_data/4_0_multi.txt +198 -0
- data/spec/support/active_record_data/4_1_diana.txt +97 -0
- data/spec/support/active_record_data/4_1_multi.txt +196 -0
- data/spec/support/active_record_data/4_2_diana.txt +109 -0
- data/spec/support/active_record_data/4_2_diana_legacy.txt +109 -0
- data/spec/support/active_record_data/4_2_multi.txt +220 -0
- data/spec/support/active_record_data/4_2_multi_legacy.txt +220 -0
- data/spec/support/active_record_data/5_0_diana.txt +105 -0
- data/spec/support/active_record_data/5_0_multi.txt +212 -0
- 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/active_record_data/6_0_diana.txt +104 -0
- data/spec/support/active_record_data/6_0_multi.txt +210 -0
- 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/active_record_data.rb +20 -0
- data/spec/support/ext_verifier.rb +42 -0
- data/spec/support/mongoid_versions.rb +26 -0
- data/spec/support/rails_versions.rb +55 -0
- metadata +104 -15
- data/lib/awesome_print/ext/no_brainer.rb +0 -58
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010-
|
1
|
+
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
2
2
|
#
|
3
3
|
# Awesome Print is freely distributable under the terms of MIT license.
|
4
4
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
@@ -15,10 +15,12 @@ module AwesomePrint
|
|
15
15
|
#------------------------------------------------------------------------------
|
16
16
|
def cast_with_active_record(object, type)
|
17
17
|
cast = cast_without_active_record(object, type)
|
18
|
-
return cast if !defined?(::ActiveRecord)
|
18
|
+
return cast if !defined?(::ActiveRecord::Base)
|
19
19
|
|
20
20
|
if object.is_a?(::ActiveRecord::Base)
|
21
21
|
cast = :active_record_instance
|
22
|
+
elsif object.is_a?(::ActiveModel::Errors)
|
23
|
+
cast = :active_model_error
|
22
24
|
elsif object.is_a?(Class) && object.ancestors.include?(::ActiveRecord::Base)
|
23
25
|
cast = :active_record_class
|
24
26
|
elsif type == :activerecord_relation || object.class.ancestors.include?(::ActiveRecord::Relation)
|
@@ -42,27 +44,58 @@ module AwesomePrint
|
|
42
44
|
return object.inspect if !defined?(::ActiveSupport::OrderedHash)
|
43
45
|
return awesome_object(object) if @options[:raw]
|
44
46
|
|
45
|
-
data = object.class.column_names.
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
data = if object.class.column_names != object.attributes.keys
|
48
|
+
object.attributes
|
49
|
+
else
|
50
|
+
object.class.column_names.inject(::ActiveSupport::OrderedHash.new) do |hash, name|
|
51
|
+
if object.has_attribute?(name) || object.new_record?
|
52
|
+
value = object.respond_to?(name) ? object.send(name) : object.read_attribute(name)
|
53
|
+
hash[name.to_sym] = value
|
54
|
+
end
|
55
|
+
hash
|
56
|
+
end
|
57
|
+
end
|
58
|
+
"#{object} #{awesome_hash(data)}"
|
53
59
|
end
|
54
60
|
|
55
61
|
# Format ActiveRecord class object.
|
56
62
|
#------------------------------------------------------------------------------
|
57
63
|
def awesome_active_record_class(object)
|
58
|
-
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:columns) || object.to_s ==
|
64
|
+
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:columns) || object.to_s == 'ActiveRecord::Base'
|
59
65
|
return awesome_class(object) if object.respond_to?(:abstract_class?) && object.abstract_class?
|
60
66
|
|
61
67
|
data = object.columns.inject(::ActiveSupport::OrderedHash.new) do |hash, c|
|
62
68
|
hash[c.name.to_sym] = c.type
|
63
69
|
hash
|
64
70
|
end
|
65
|
-
|
71
|
+
|
72
|
+
name = "class #{awesome_simple(object.to_s, :class)}"
|
73
|
+
base = "< #{awesome_simple(object.superclass.to_s, :class)}"
|
74
|
+
|
75
|
+
[name, base, awesome_hash(data)].join(' ')
|
76
|
+
end
|
77
|
+
|
78
|
+
# Format ActiveModel error object.
|
79
|
+
#------------------------------------------------------------------------------
|
80
|
+
def awesome_active_model_error(object)
|
81
|
+
return object.inspect if !defined?(::ActiveSupport::OrderedHash)
|
82
|
+
return awesome_object(object) if @options[:raw]
|
83
|
+
|
84
|
+
object_dump = object.marshal_dump.first
|
85
|
+
data = if object_dump.class.column_names != object_dump.attributes.keys
|
86
|
+
object_dump.attributes
|
87
|
+
else
|
88
|
+
object_dump.class.column_names.inject(::ActiveSupport::OrderedHash.new) do |hash, name|
|
89
|
+
if object_dump.has_attribute?(name) || object_dump.new_record?
|
90
|
+
value = object_dump.respond_to?(name) ? object_dump.send(name) : object_dump.read_attribute(name)
|
91
|
+
hash[name.to_sym] = value
|
92
|
+
end
|
93
|
+
hash
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
data.merge!({details: object.details, messages: object.messages})
|
98
|
+
"#{object} #{awesome_hash(data)}"
|
66
99
|
end
|
67
100
|
end
|
68
101
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010-
|
1
|
+
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
2
2
|
#
|
3
3
|
# Awesome Print is freely distributable under the terms of MIT license.
|
4
4
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
@@ -18,7 +18,7 @@ module AwesomePrint
|
|
18
18
|
cast = cast_without_mongo_mapper(object, type)
|
19
19
|
|
20
20
|
if defined?(::MongoMapper::Document)
|
21
|
-
if object.is_a?(Class) && (object.ancestors & [
|
21
|
+
if object.is_a?(Class) && (object.ancestors & [::MongoMapper::Document, ::MongoMapper::EmbeddedDocument]).size > 0
|
22
22
|
cast = :mongo_mapper_class
|
23
23
|
elsif object.is_a?(::MongoMapper::Document) || object.is_a?(::MongoMapper::EmbeddedDocument)
|
24
24
|
cast = :mongo_mapper_instance
|
@@ -38,7 +38,7 @@ module AwesomePrint
|
|
38
38
|
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:keys)
|
39
39
|
|
40
40
|
data = object.keys.sort.inject(::ActiveSupport::OrderedHash.new) do |hash, c|
|
41
|
-
hash[c.first] = (c.last.type ||
|
41
|
+
hash[c.first] = (c.last.type || 'undefined').to_s.underscore.intern
|
42
42
|
hash
|
43
43
|
end
|
44
44
|
|
@@ -49,7 +49,10 @@ module AwesomePrint
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
"class #{object
|
52
|
+
name = "class #{awesome_simple(object.to_s, :class)}"
|
53
|
+
base = "< #{awesome_simple(object.superclass.to_s, :class)}"
|
54
|
+
|
55
|
+
[name, base, awesome_hash(data)].join(' ')
|
53
56
|
end
|
54
57
|
|
55
58
|
# Format MongoMapper instance object.
|
@@ -65,7 +68,7 @@ module AwesomePrint
|
|
65
68
|
return object.inspect if !defined?(::ActiveSupport::OrderedHash)
|
66
69
|
return awesome_object(object) if @options[:raw]
|
67
70
|
|
68
|
-
data = object.keys.keys.sort_by{|k| k}.inject(::ActiveSupport::OrderedHash.new) do |hash, name|
|
71
|
+
data = object.keys.keys.sort_by { |k| k }.inject(::ActiveSupport::OrderedHash.new) do |hash, name|
|
69
72
|
hash[name] = object[name]
|
70
73
|
hash
|
71
74
|
end
|
@@ -73,11 +76,11 @@ module AwesomePrint
|
|
73
76
|
# Add in associations
|
74
77
|
if @options[:mongo_mapper][:show_associations]
|
75
78
|
object.associations.each do |name, assoc|
|
76
|
-
if @options[:mongo_mapper][:inline_embedded] and assoc.embeddable?
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
79
|
+
data[name.to_s] = if @options[:mongo_mapper][:inline_embedded] and assoc.embeddable?
|
80
|
+
object.send(name)
|
81
|
+
else
|
82
|
+
assoc
|
83
|
+
end
|
81
84
|
end
|
82
85
|
end
|
83
86
|
|
@@ -93,7 +96,7 @@ module AwesomePrint
|
|
93
96
|
return object.inspect if !defined?(::ActiveSupport::OrderedHash)
|
94
97
|
return awesome_object(object) if @options[:raw]
|
95
98
|
|
96
|
-
association = object.class.name.split('::').last.titleize.downcase.sub(/ association$/,'')
|
99
|
+
association = object.class.name.split('::').last.titleize.downcase.sub(/ association$/, '')
|
97
100
|
association = "embeds #{association}" if object.embeddable?
|
98
101
|
class_name = object.class_name
|
99
102
|
|
@@ -111,8 +114,8 @@ module AwesomePrint
|
|
111
114
|
def apply_default_mongo_mapper_options
|
112
115
|
@options[:color][:assoc] ||= :greenish
|
113
116
|
@options[:mongo_mapper] ||= {
|
114
|
-
:
|
115
|
-
:
|
117
|
+
show_associations: false, # Display association data for MongoMapper documents and classes.
|
118
|
+
inline_embedded: false # Display embedded associations inline with MongoMapper documents.
|
116
119
|
}
|
117
120
|
end
|
118
121
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010-
|
1
|
+
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
2
2
|
#
|
3
3
|
# Awesome Print is freely distributable under the terms of MIT license.
|
4
4
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
@@ -33,10 +33,14 @@ module AwesomePrint
|
|
33
33
|
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:fields)
|
34
34
|
|
35
35
|
data = object.fields.sort_by { |key| key }.inject(::ActiveSupport::OrderedHash.new) do |hash, c|
|
36
|
-
hash[c[1].name.to_sym] = (c[1].type ||
|
36
|
+
hash[c[1].name.to_sym] = (c[1].type || 'undefined').to_s.underscore.intern
|
37
37
|
hash
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
|
+
name = "class #{awesome_simple(object.to_s, :class)}"
|
41
|
+
base = "< #{awesome_simple(object.superclass.to_s, :class)}"
|
42
|
+
|
43
|
+
[name, base, awesome_hash(data)].join(' ')
|
40
44
|
end
|
41
45
|
|
42
46
|
# Format Mongoid Document object.
|
@@ -48,9 +52,7 @@ module AwesomePrint
|
|
48
52
|
hash[c[0].to_sym] = c[1]
|
49
53
|
hash
|
50
54
|
end
|
51
|
-
if !object.errors.empty?
|
52
|
-
data = {:errors => object.errors, :attributes => data}
|
53
|
-
end
|
55
|
+
data = { errors: object.errors, attributes: data } if !object.errors.empty?
|
54
56
|
"#{object} #{awesome_hash(data)}"
|
55
57
|
end
|
56
58
|
|
@@ -0,0 +1,52 @@
|
|
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
|
+
module AwesomePrint
|
7
|
+
module NoBrainer
|
8
|
+
|
9
|
+
def self.included(base)
|
10
|
+
base.send :alias_method, :cast_without_nobrainer, :cast
|
11
|
+
base.send :alias_method, :cast, :cast_with_nobrainer
|
12
|
+
end
|
13
|
+
|
14
|
+
# Add NoBrainer class names to the dispatcher pipeline.
|
15
|
+
#------------------------------------------------------------------------------
|
16
|
+
def cast_with_nobrainer(object, type)
|
17
|
+
cast = cast_without_nobrainer(object, type)
|
18
|
+
if defined?(::NoBrainer::Document)
|
19
|
+
if object.is_a?(Class) && object < ::NoBrainer::Document
|
20
|
+
cast = :nobrainer_class
|
21
|
+
elsif object.is_a?(::NoBrainer::Document)
|
22
|
+
cast = :nobrainer_document
|
23
|
+
end
|
24
|
+
end
|
25
|
+
cast
|
26
|
+
end
|
27
|
+
|
28
|
+
# Format NoBrainer class object.
|
29
|
+
#------------------------------------------------------------------------------
|
30
|
+
def awesome_nobrainer_class(object)
|
31
|
+
name = "#{awesome_simple(object, :class)} < #{awesome_simple(object.superclass, :class)}"
|
32
|
+
data = Hash[object.fields.map do |field, options|
|
33
|
+
[field, (options[:type] || Object).to_s.underscore.to_sym]
|
34
|
+
end]
|
35
|
+
|
36
|
+
name = "class #{awesome_simple(object.to_s, :class)}"
|
37
|
+
base = "< #{awesome_simple(object.superclass.to_s, :class)}"
|
38
|
+
|
39
|
+
[name, base, awesome_hash(data)].join(' ')
|
40
|
+
end
|
41
|
+
|
42
|
+
# Format NoBrainer Document object.
|
43
|
+
#------------------------------------------------------------------------------
|
44
|
+
def awesome_nobrainer_document(object)
|
45
|
+
data = object.inspectable_attributes.symbolize_keys
|
46
|
+
data = { errors: object.errors, attributes: data } if object.errors.present?
|
47
|
+
"#{object} #{awesome_hash(data)}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
AwesomePrint::Formatter.send(:include, AwesomePrint::NoBrainer)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010-
|
1
|
+
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
2
2
|
#
|
3
3
|
# Awesome Print is freely distributable under the terms of MIT license.
|
4
4
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
@@ -15,7 +15,7 @@ module AwesomePrint
|
|
15
15
|
#------------------------------------------------------------------------------
|
16
16
|
def cast_with_nokogiri(object, type)
|
17
17
|
cast = cast_without_nokogiri(object, type)
|
18
|
-
if (defined?(::Nokogiri::XML::Node) && object.is_a?(::Nokogiri::XML::Node)) ||
|
18
|
+
if (defined?(::Nokogiri::XML::Node) && object.is_a?(::Nokogiri::XML::Node)) ||
|
19
19
|
(defined?(::Nokogiri::XML::NodeSet) && object.is_a?(::Nokogiri::XML::NodeSet))
|
20
20
|
cast = :nokogiri_xml_node
|
21
21
|
end
|
@@ -25,9 +25,9 @@ module AwesomePrint
|
|
25
25
|
#------------------------------------------------------------------------------
|
26
26
|
def awesome_nokogiri_xml_node(object)
|
27
27
|
if object.is_a?(::Nokogiri::XML::NodeSet) && object.empty?
|
28
|
-
return
|
28
|
+
return '[]'
|
29
29
|
end
|
30
|
-
xml = object.to_xml(:
|
30
|
+
xml = object.to_xml(indent: 2)
|
31
31
|
#
|
32
32
|
# Colorize tag, id/class name, and contents.
|
33
33
|
#
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010-
|
1
|
+
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
2
2
|
#
|
3
3
|
# Awesome Print is freely distributable under the terms of MIT license.
|
4
4
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
@@ -60,11 +60,10 @@ module AwesomePrint
|
|
60
60
|
def awesome_ripple_document_class(object)
|
61
61
|
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:properties)
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
"class #{object} < #{object.superclass} " << awesome_hash(data)
|
63
|
+
name = "class #{awesome_simple(object.to_s, :class)}"
|
64
|
+
base = "< #{awesome_simple(object.superclass.to_s, :class)}"
|
65
|
+
|
66
|
+
[name, base, awesome_hash(data)].join(' ')
|
68
67
|
end
|
69
68
|
end
|
70
69
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010-
|
1
|
+
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
2
2
|
#
|
3
3
|
# Awesome Print is freely distributable under the terms of MIT license.
|
4
4
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
@@ -32,9 +32,7 @@ module AwesomePrint
|
|
32
32
|
hash[c[0].to_sym] = c[1]
|
33
33
|
hash
|
34
34
|
end
|
35
|
-
if !object.errors.empty?
|
36
|
-
data = {:errors => object.errors, :values => data}
|
37
|
-
end
|
35
|
+
data = { errors: object.errors, values: data } if !object.errors.empty?
|
38
36
|
"#{object} #{awesome_hash(data)}"
|
39
37
|
end
|
40
38
|
|
@@ -47,8 +45,11 @@ module AwesomePrint
|
|
47
45
|
# Format Sequel Model class.
|
48
46
|
#------------------------------------------------------------------------------
|
49
47
|
def awesome_sequel_model_class(object)
|
50
|
-
data = object.db_schema.inject({}) {|h, (
|
51
|
-
"class #{object
|
48
|
+
data = object.db_schema.inject({}) { |h, (prop, defn)| h.merge(prop => defn[:db_type]) }
|
49
|
+
name = "class #{awesome_simple(object.to_s, :class)}"
|
50
|
+
base = "< #{awesome_simple(object.superclass.to_s, :class)}"
|
51
|
+
|
52
|
+
[name, base, awesome_hash(data)].join(' ')
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|