# frozen_string_literal: true# typed: truemoduleT::Props::PrettyPrintableincludeT::Props::Plugin# Return a string representation of this object and all of its propsdefinspectT.unsafe(T.cast(self,Object).class).decorator.inspect_instance(self)end# Override the PP gem with something that's similar, but gives us a hook# to do redactiondefpretty_inspectT.unsafe(T.cast(self,Object).class).decorator.inspect_instance(self,multiline: true)endmoduleDecoratorMethodsextendT::Sigsig{returns(T::Array[Symbol])}defvalid_propssuper+[:inspect]endsigdoparams(instance: T::Props::PrettyPrintable,multiline: T::Boolean,indent: String).returns(String)enddefinspect_instance(instance,multiline: false,indent: ' ')components=inspect_instance_components(instance,multiline: multiline,indent: indent).reject(&:empty?)# Not using #<> here as that makes pry highlight these objects# as if they were all comments, whereas this makes them look# like the structured thing they are.ifmultiline"#{components[0]}:\n"+T.must(components[1..-1]).join("\n")else"<#{components.join(' ')}>"endendsigdoparams(instance: T::Props::PrettyPrintable,multiline: T::Boolean,indent: String).returns(T::Array[String])endprivatedefinspect_instance_components(instance,multiline:,indent:)pretty_props=T.unsafe(self).all_props.mapdo|prop|[prop,inspect_prop_value(instance,prop,multiline: multiline,indent: indent)]endjoined_props=join_props_with_pretty_values(pretty_props,multiline: multiline,indent: indent)[T.unsafe(self).decorated_class.to_s,joined_props,]endsigdoparams(instance: T::Props::PrettyPrintable,prop: Symbol,multiline: T::Boolean,indent: String).returns(String).checked(:never)endprivatedefinspect_prop_value(instance,prop,multiline:,indent:)val=T.unsafe(self).get(instance,prop)rules=T.unsafe(self).prop_rules(prop)if(custom_inspect=rules[:inspect])ifT::Utils.arity(custom_inspect)==1custom_inspect.call(val)elsecustom_inspect.call(val,{multiline: multiline,indent: indent})endelsifrules[:sensitivity]&&!rules[:sensitivity].empty?&&!val.nil?"<REDACTED #{rules[:sensitivity].join(', ')}>"elseval.inspectendendsigdoparams(pretty_kvs: T::Array[[Symbol,String]],multiline: T::Boolean,indent: String).returns(String)endprivatedefjoin_props_with_pretty_values(pretty_kvs,multiline:,indent: ' ')pairs=pretty_kvs.sort_by{|k,_v|k.to_s}.map{|k,v|"#{k}=#{v}"}ifmultilineindent+pairs.join("\n#{indent}")elsepairs.join(', ')endendendend