awesome_print 1.7.0 → 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 +44 -34
- data/CHANGELOG.md +28 -0
- data/CONTRIBUTING.md +2 -1
- data/Gemfile.lock +25 -33
- data/LICENSE +16 -19
- data/README.md +88 -44
- 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 +1 -1
- 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 +8 -5
- 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 +28 -28
- data/lib/awesome_print/formatters/array_formatter.rb +108 -42
- data/lib/awesome_print/formatters/base_formatter.rb +16 -14
- data/lib/awesome_print/formatters/class_formatter.rb +2 -1
- data/lib/awesome_print/formatters/dir_formatter.rb +1 -1
- data/lib/awesome_print/formatters/file_formatter.rb +1 -1
- data/lib/awesome_print/formatters/hash_formatter.rb +74 -22
- data/lib/awesome_print/formatters/object_formatter.rb +13 -15
- data/lib/awesome_print/formatters/struct_formatter.rb +71 -0
- data/lib/awesome_print/formatters.rb +15 -0
- data/lib/awesome_print/inspector.rb +83 -96
- data/lib/awesome_print/version.rb +2 -2
- data/lib/awesome_print.rb +18 -17
- data/spec/active_record_helper.rb +8 -2
- data/spec/colors_spec.rb +30 -30
- 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 +193 -165
- data/spec/methods_spec.rb +125 -129
- data/spec/misc_spec.rb +95 -92
- data/spec/objects_spec.rb +119 -28
- data/spec/spec_helper.rb +29 -10
- 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 +90 -26
@@ -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
|
@@ -12,24 +12,24 @@
|
|
12
12
|
#
|
13
13
|
# If you could think of a better way please let me know :-)
|
14
14
|
#
|
15
|
-
|
16
|
-
[ :-, :& ].each do |operator|
|
17
|
-
original_operator = instance_method(operator)
|
15
|
+
module AwesomeMethodArray #:nodoc:
|
18
16
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
17
|
+
def -(_other_ary)
|
18
|
+
super.tap do |arr|
|
19
|
+
arr.instance_variable_set(:@__awesome_methods__, self.instance_variable_get(:@__awesome_methods__))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def &(_other_ary)
|
24
|
+
super.tap do |arr|
|
25
|
+
arr.instance_variable_set(:@__awesome_methods__, self.instance_variable_get(:@__awesome_methods__))
|
26
26
|
end
|
27
27
|
end
|
28
|
+
|
28
29
|
#
|
29
30
|
# Intercepting Array#grep needs a special treatment since grep accepts
|
30
31
|
# an optional block.
|
31
32
|
#
|
32
|
-
alias :original_grep :grep
|
33
33
|
def grep(pattern, &blk)
|
34
34
|
#
|
35
35
|
# The following looks rather insane and I've sent numerous hours trying
|
@@ -55,9 +55,9 @@ class Array #:nodoc:
|
|
55
55
|
# the comment :-)
|
56
56
|
#
|
57
57
|
arr = unless blk
|
58
|
-
|
58
|
+
super(pattern)
|
59
59
|
else
|
60
|
-
|
60
|
+
super(pattern) do |match|
|
61
61
|
#
|
62
62
|
# The binding can only be used with Ruby-defined methods, therefore
|
63
63
|
# we must rescue potential "ArgumentError: Can't create Binding from
|
@@ -72,10 +72,8 @@ class Array #:nodoc:
|
|
72
72
|
yield match
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
76
|
-
|
77
|
-
arr.reject! { |item| !(item.is_a?(Symbol) || item.is_a?(String)) } # grep block might return crap.
|
78
|
-
end
|
75
|
+
arr.instance_variable_set(:@__awesome_methods__, self.instance_variable_get(:@__awesome_methods__))
|
76
|
+
arr.reject! { |item| !(item.is_a?(Symbol) || item.is_a?(String)) } # grep block might return crap.
|
79
77
|
arr
|
80
78
|
end
|
81
79
|
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
|
@@ -15,7 +15,8 @@ class Class #:nodoc:
|
|
15
15
|
|
16
16
|
define_method name do |*args|
|
17
17
|
methods = original_method.bind(self).call(*args)
|
18
|
-
methods.instance_variable_set(
|
18
|
+
methods.instance_variable_set(:@__awesome_methods__, self)
|
19
|
+
methods.extend(AwesomeMethodArray)
|
19
20
|
methods
|
20
21
|
end
|
21
22
|
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,4 +18,4 @@ unless nil.method(:class).respond_to?(:name)
|
|
18
18
|
inspect.split(/[#.>]/)[-1]
|
19
19
|
end
|
20
20
|
end
|
21
|
-
end
|
21
|
+
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
|
@@ -15,7 +15,8 @@ class Object #:nodoc:
|
|
15
15
|
|
16
16
|
define_method name do |*args|
|
17
17
|
methods = original_method.bind(self).call(*args)
|
18
|
-
methods.instance_variable_set(
|
18
|
+
methods.instance_variable_set(:@__awesome_methods__, self)
|
19
|
+
methods.extend(AwesomeMethodArray)
|
19
20
|
methods
|
20
21
|
end
|
21
22
|
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
|
@@ -17,11 +17,11 @@ class String
|
|
17
17
|
%w(gray red green yellow blue purple cyan white).zip(
|
18
18
|
%w(black darkred darkgreen brown navy darkmagenta darkcyan slategray)).each_with_index do |(color, shade), i|
|
19
19
|
define_method color do |*html|
|
20
|
-
html[0] ? %Q|<kbd style="color:#{color}">#{self}</kbd>| : "\e[1;#{30+i}m#{self}\e[0m"
|
20
|
+
html[0] ? %Q|<kbd style="color:#{color}">#{self}</kbd>| : "\e[1;#{30 + i}m#{self}\e[0m"
|
21
21
|
end
|
22
22
|
|
23
23
|
define_method "#{color}ish" do |*html|
|
24
|
-
html[0] ? %Q|<kbd style="color:#{shade}">#{self}</kbd>| : "\e[0;#{30+i}m#{self}\e[0m"
|
24
|
+
html[0] ? %Q|<kbd style="color:#{shade}">#{self}</kbd>| : "\e[0;#{30 + i}m#{self}\e[0m"
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module AwesomePrint
|
2
|
+
class << self
|
3
|
+
attr_accessor :defaults, :force_colors
|
4
|
+
|
5
|
+
# Class accessor to force colorized output (ex. forked subprocess where TERM
|
6
|
+
# might be dumb).
|
7
|
+
#---------------------------------------------------------------------------
|
8
|
+
def force_colors!(value = true)
|
9
|
+
@force_colors = value
|
10
|
+
end
|
11
|
+
|
12
|
+
def console?
|
13
|
+
boolean(defined?(IRB) || defined?(Pry))
|
14
|
+
end
|
15
|
+
|
16
|
+
def rails_console?
|
17
|
+
console? && boolean(defined?(Rails::Console) || ENV['RAILS_ENV'])
|
18
|
+
end
|
19
|
+
|
20
|
+
def diet_rb
|
21
|
+
IRB.formatter = Class.new(IRB::Formatter) do
|
22
|
+
def inspect_object(object)
|
23
|
+
object.ai
|
24
|
+
end
|
25
|
+
end.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def usual_rb
|
29
|
+
IRB::Irb.class_eval do
|
30
|
+
def output_value(*args)
|
31
|
+
ap @context.last_value
|
32
|
+
rescue NoMethodError
|
33
|
+
puts "(Object doesn't support #ai)"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def irb!
|
39
|
+
return unless defined?(IRB)
|
40
|
+
|
41
|
+
IRB.version.include?('DietRB') ? diet_rb : usual_rb
|
42
|
+
end
|
43
|
+
|
44
|
+
def pry!
|
45
|
+
Pry.print = proc { |output, value| output.puts value.ai } if defined?(Pry)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# Takes a value and returns true unless it is false or nil
|
51
|
+
# This is an alternative to the less readable !!(value)
|
52
|
+
# https://github.com/bbatsov/ruby-style-guide#no-bang-bang
|
53
|
+
def boolean(value)
|
54
|
+
value ? true : false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,17 +1,21 @@
|
|
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
|
5
5
|
#------------------------------------------------------------------------------
|
6
6
|
module AwesomePrint
|
7
7
|
module ActionView
|
8
|
-
|
9
8
|
# Use HTML colors and add default "debug_dump" class to the resulting HTML.
|
10
9
|
def ap_debug(object, options = {})
|
11
|
-
object.ai(
|
10
|
+
object.ai(
|
11
|
+
options.merge(html: true)
|
12
|
+
).sub(
|
13
|
+
/^<pre([\s>])/,
|
14
|
+
'<pre class="debug_dump"\\1'
|
15
|
+
)
|
12
16
|
end
|
13
17
|
|
14
|
-
|
18
|
+
alias ap ap_debug
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
@@ -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
|
|
@@ -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
|
@@ -28,19 +28,22 @@ module AwesomePrint
|
|
28
28
|
# Format NoBrainer class object.
|
29
29
|
#------------------------------------------------------------------------------
|
30
30
|
def awesome_nobrainer_class(object)
|
31
|
+
name = "#{awesome_simple(object, :class)} < #{awesome_simple(object.superclass, :class)}"
|
31
32
|
data = Hash[object.fields.map do |field, options|
|
32
33
|
[field, (options[:type] || Object).to_s.underscore.to_sym]
|
33
34
|
end]
|
34
|
-
|
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(' ')
|
35
40
|
end
|
36
41
|
|
37
42
|
# Format NoBrainer Document object.
|
38
43
|
#------------------------------------------------------------------------------
|
39
44
|
def awesome_nobrainer_document(object)
|
40
45
|
data = object.inspectable_attributes.symbolize_keys
|
41
|
-
if object.errors.present?
|
42
|
-
data = {:errors => object.errors, :attributes => data}
|
43
|
-
end
|
46
|
+
data = { errors: object.errors, attributes: data } if object.errors.present?
|
44
47
|
"#{object} #{awesome_hash(data)}"
|
45
48
|
end
|
46
49
|
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
|
@@ -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
|
|