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:
parent
930be54e7a
commit
36e486dbc1
4 changed files with 56 additions and 1 deletions
|
@ -43,6 +43,8 @@ sort_keys: false, # Do not sort hash keys.
|
||||||
sort_vars: true, # Sort instance variables.
|
sort_vars: true, # Sort instance variables.
|
||||||
limit: false, # Limit arrays & hashes. Accepts bool or int.
|
limit: false, # Limit arrays & hashes. Accepts bool or int.
|
||||||
ruby19_syntax: false, # Use Ruby 1.9 hash syntax in output.
|
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: {
|
color: {
|
||||||
args: :pale,
|
args: :pale,
|
||||||
array: :white,
|
array: :white,
|
||||||
|
|
|
@ -60,7 +60,9 @@ module AwesomePrint
|
||||||
end
|
end
|
||||||
|
|
||||||
def awesome_instance
|
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
|
end
|
||||||
|
|
||||||
def left_aligned
|
def left_aligned
|
||||||
|
|
|
@ -23,6 +23,8 @@ module AwesomePrint
|
||||||
sort_vars: true, # Sort instance variables.
|
sort_vars: true, # Sort instance variables.
|
||||||
limit: false, # Limit arrays & hashes. Accepts bool or int.
|
limit: false, # Limit arrays & hashes. Accepts bool or int.
|
||||||
ruby19_syntax: false, # Use Ruby 1.9 hash syntax in output.
|
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: {
|
color: {
|
||||||
args: :pale,
|
args: :pale,
|
||||||
array: :white,
|
array: :white,
|
||||||
|
|
|
@ -167,5 +167,54 @@ EOS
|
||||||
expect(out).to be_similar_to(str)
|
expect(out).to be_similar_to(str)
|
||||||
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue