Module: T::Props::PrettyPrintable
Defined Under Namespace
Modules: DecoratorMethods
Constant Summary
Constants included from Helpers
Instance Method Summary collapse
-
#inspect ⇒ Object
Return a string representation of this object and all of its props in a single line.
-
#pretty_inspect ⇒ Object
Return a pretty string representation of this object and all of its props.
-
#pretty_print(pp) ⇒ Object
Override the PP gem with something that’s similar, but gives us a hook to do redaction and customization.
Methods included from Helpers
#abstract!, #final!, #interface!, #mixes_in_class_methods, #requires_ancestor, #sealed!
Methods included from Sig
Instance Method Details
#inspect ⇒ Object
Return a string representation of this object and all of its props in a single line
36 37 38 39 40 |
# File 'lib/types/props/pretty_printable.rb', line 36 def inspect string = +"" PP.singleline_pp(self, string) string end |
#pretty_inspect ⇒ Object
Return a pretty string representation of this object and all of its props
43 44 45 46 47 |
# File 'lib/types/props/pretty_printable.rb', line 43 def pretty_inspect string = +"" PP.pp(self, string) string end |
#pretty_print(pp) ⇒ Object
Override the PP gem with something that’s similar, but gives us a hook to do redaction and customization
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/types/props/pretty_printable.rb', line 9 def pretty_print(pp) clazz = T.unsafe(T.cast(self, Object).class).decorator multiline = pp.is_a?(PP) pp.group(1, "<#{clazz.inspect_class_with_decoration(self)}", ">") do clazz.all_props.sort.each do |prop| pp.breakable val = clazz.get(self, prop) rules = clazz.prop_rules(prop) pp.text("#{prop}=") if (custom_inspect = rules[:inspect]) inspected = if T::Utils.arity(custom_inspect) == 1 custom_inspect.call(val) else custom_inspect.call(val, {multiline: multiline}) end pp.text(inspected.nil? ? "nil" : inspected) elsif rules[:sensitivity] && !rules[:sensitivity].empty? && !val.nil? pp.text("<REDACTED #{rules[:sensitivity].join(', ')}>") else val.pretty_print(pp) end end clazz.pretty_print_extra(self, pp) end end |