Skip to content

Commit

Permalink
lowering the verbosity of SchemaInstanceBase#inspect. only show the s…
Browse files Browse the repository at this point in the history
…chema id if the class is not explicitly named, and drop the class of the instance
  • Loading branch information
notEthan committed Jun 16, 2018
1 parent 42df6f1 commit 5e0c306
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
15 changes: 12 additions & 3 deletions lib/scorpio/schema_instance_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ def inspect
%Q(#{name} (#{schema_id}))
end
end
def to_s
if !respond_to?(:schema)
super
elsif !name || name =~ /\AScorpio::SchemaClasses::/
%Q(#{SchemaClasses.inspect}[#{schema_id.inspect}])
else
name
end
end

def schema_classes_const_name
name = schema.schema_id.gsub(/[^\w]/, '_')
Expand Down Expand Up @@ -86,11 +95,11 @@ def validate!
schema.validate!(instance)
end
def inspect
"\#<#{self.class.inspect} #{instance.inspect}>"
"\#<#{self.class.to_s} #{instance.inspect}>"
end
def pretty_print(q)
q.instance_exec(self) do |obj|
text "\#<#{obj.class.inspect}"
text "\#<#{obj.class.to_s}"
group_sub {
nest(2) {
breakable ' '
Expand All @@ -103,7 +112,7 @@ def pretty_print(q)
end

def object_group_text
instance.class.inspect + ' ' + instance.object_group_text
instance.object_group_text
end

def fingerprint
Expand Down
8 changes: 4 additions & 4 deletions lib/scorpio/typelike_modules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module Hashlike

def inspect
object_group_text = respond_to?(:object_group_text) ? ' ' + self.object_group_text : ''
"\#{<#{self.class.inspect}#{object_group_text}>#{empty? ? '' : ' '}#{self.map { |k, v| "#{k.inspect} => #{v.inspect}" }.join(', ')}}"
"\#{<#{self.class.to_s}#{object_group_text}>#{empty? ? '' : ' '}#{self.map { |k, v| "#{k.inspect} => #{v.inspect}" }.join(', ')}}"
end

def to_s
Expand All @@ -77,7 +77,7 @@ def to_s
def pretty_print(q)
q.instance_exec(self) do |obj|
object_group_text = obj.respond_to?(:object_group_text) ? ' ' + obj.object_group_text : ''
text "\#{<#{obj.class.inspect}#{object_group_text}>"
text "\#{<#{obj.class.to_s}#{object_group_text}>"
group_sub {
nest(2) {
breakable(obj.any? { true } ? ' ' : '')
Expand Down Expand Up @@ -133,7 +133,7 @@ module Arraylike

def inspect
object_group_text = respond_to?(:object_group_text) ? ' ' + self.object_group_text : ''
"\#[<#{self.class.inspect}#{object_group_text}>#{empty? ? '' : ' '}#{self.map { |e| e.inspect }.join(', ')}]"
"\#[<#{self.class.to_s}#{object_group_text}>#{empty? ? '' : ' '}#{self.map { |e| e.inspect }.join(', ')}]"
end

def to_s
Expand All @@ -143,7 +143,7 @@ def to_s
def pretty_print(q)
q.instance_exec(self) do |obj|
object_group_text = obj.respond_to?(:object_group_text) ? ' ' + obj.object_group_text : ''
text "\#[<#{obj.class.inspect}#{object_group_text}>"
text "\#[<#{obj.class.to_s}#{object_group_text}>"
group_sub {
nest(2) {
breakable(obj.any? { true } ? ' ' : '')
Expand Down

0 comments on commit 5e0c306

Please sign in to comment.