mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Added :raw => false option to avoid deep object formatting by default
This commit is contained in:
parent
10efa1d60a
commit
0872a955b7
4 changed files with 18 additions and 7 deletions
|
@ -22,6 +22,7 @@ Default options:
|
|||
:html => false, # Use ANSI color codes rather than HTML.
|
||||
:multiline => true, # Display in multiple lines.
|
||||
:plain => false, # Use colors.
|
||||
:raw => false, # Do not recursively format object instance variables.
|
||||
:sort_keys => false, # Do not sort hash keys.
|
||||
:limit => false, # Limit large output for arrays and hashes. Set to a boolean or integer.
|
||||
:color => {
|
||||
|
|
|
@ -61,8 +61,11 @@ module AwesomePrint
|
|||
# Catch all method to format an arbitrary object.
|
||||
#------------------------------------------------------------------------------
|
||||
def awesome_self(object, type)
|
||||
return awesome_object(object) if object.instance_variables.any?
|
||||
colorize(object.inspect.to_s, type)
|
||||
if @options[:raw] && object.instance_variables.any?
|
||||
awesome_object(object)
|
||||
else
|
||||
colorize(object.inspect.to_s, type)
|
||||
end
|
||||
end
|
||||
|
||||
# Format an array.
|
||||
|
|
|
@ -59,6 +59,7 @@ module AwesomePrint
|
|||
:html => false, # Use ANSI color codes rather than HTML.
|
||||
:multiline => true, # Display in multiple lines.
|
||||
:plain => false, # Use colors.
|
||||
:raw => false, # Do not recursively format object instance variables.
|
||||
:sort_keys => false, # Do not sort hash keys.
|
||||
:limit => false, # Limit large output for arrays and hashes. Set to a boolean or integer.
|
||||
:color => {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
||||
|
||||
describe "Single method" do
|
||||
describe "Objects" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
@ -9,7 +9,7 @@ describe "Single method" do
|
|||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||
end
|
||||
|
||||
describe "object" do
|
||||
describe "Formatting an object" do
|
||||
it "attributes" do
|
||||
class Hello
|
||||
attr_reader :abra
|
||||
|
@ -21,7 +21,8 @@ describe "Single method" do
|
|||
end
|
||||
end
|
||||
|
||||
out = Hello.new.ai(:plain => true)
|
||||
hello = Hello.new
|
||||
out = hello.ai(:plain => true, :raw => true)
|
||||
str = <<-EOS.strip
|
||||
#<Hello:0x01234567
|
||||
attr_accessor :dabra = 3,
|
||||
|
@ -30,6 +31,7 @@ describe "Single method" do
|
|||
>
|
||||
EOS
|
||||
out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str
|
||||
hello.ai(:plain => true, :raw => false).should == hello.inspect
|
||||
end
|
||||
|
||||
it "instance variables" do
|
||||
|
@ -39,7 +41,8 @@ EOS
|
|||
end
|
||||
end
|
||||
|
||||
out = Hello.new.ai(:plain => true)
|
||||
hello = Hello.new
|
||||
out = hello.ai(:plain => true, :raw => true)
|
||||
str = <<-EOS.strip
|
||||
#<Hello:0x01234567
|
||||
@abra = 1,
|
||||
|
@ -48,6 +51,7 @@ EOS
|
|||
>
|
||||
EOS
|
||||
out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str
|
||||
hello.ai(:plain => true, :raw => false).should == hello.inspect
|
||||
end
|
||||
|
||||
it "attributes and instance variables" do
|
||||
|
@ -62,7 +66,8 @@ EOS
|
|||
end
|
||||
end
|
||||
|
||||
out = Hello.new.ai(:plain => true)
|
||||
hello = Hello.new
|
||||
out = hello.ai(:plain => true, :raw => true)
|
||||
str = <<-EOS.strip
|
||||
#<Hello:0x01234567
|
||||
@doo = 1,
|
||||
|
@ -74,6 +79,7 @@ EOS
|
|||
>
|
||||
EOS
|
||||
out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str
|
||||
hello.ai(:plain => true, :raw => false).should == hello.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue