1
0
Fork 0
mirror of https://github.com/awesome-print/awesome_print synced 2023-03-27 23:22:34 -04:00

options classname and object_id

# Conflicts:
#	spec/objects_spec.rb
This commit is contained in:
Aaron Heesakkers 2017-01-10 14:48:36 +01:00 committed by James Cox
parent 930be54e7a
commit 36e486dbc1
4 changed files with 56 additions and 1 deletions

View file

@ -43,6 +43,8 @@ sort_keys: false, # Do not sort hash keys.
sort_vars: true, # Sort instance variables.
limit: false, # Limit arrays & hashes. Accepts bool or int.
ruby19_syntax: false, # Use Ruby 1.9 hash syntax in output.
class_name: :class, # Method called to report the instance class name. (e.g. :to_s)
object_id: true, # Show object id.
color: {
args: :pale,
array: :white,

View file

@ -60,7 +60,9 @@ module AwesomePrint
end
def awesome_instance
"#{object.class}:0x%08x" % (object.__id__ * 2)
str = object.send(options[:class_name]).to_s
str << ":0x%08x" % (object.__id__ * 2) if options[:object_id]
str
end
def left_aligned

View file

@ -23,6 +23,8 @@ module AwesomePrint
sort_vars: true, # Sort instance variables.
limit: false, # Limit arrays & hashes. Accepts bool or int.
ruby19_syntax: false, # Use Ruby 1.9 hash syntax in output.
class_name: :class, # Method used to get Instance class name.
object_id: true, # Show object_id.
color: {
args: :pale,
array: :white,

View file

@ -167,5 +167,54 @@ EOS
expect(out).to be_similar_to(str)
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
end
it 'object_id' do
class Hello
def initialize
@abra = 1
@ca = 2
@dabra = 3
end
end
hello = Hello.new
out = hello.ai(plain: true, raw: true, object_id: false)
str = <<-EOS.strip
#<Hello
@abra = 1,
@ca = 2,
@dabra = 3
>
EOS
expect(out).to be_similar_to(str)
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
end
it 'class_name' do
class Hello
def initialize
@abra = 1
@ca = 2
@dabra = 3
end
def to_s
"CustomizedHello"
end
end
hello = Hello.new
out = hello.ai(plain: true, raw: true, class_name: :to_s)
str = <<-EOS.strip
#<CustomizedHello:placeholder_id
@abra = 1,
@ca = 2,
@dabra = 3
>
EOS
expect(out).to be_similar_to(str)
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
end
end
end