sorbet-runtime 0.5.10588 → 0.5.10590
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/types/props/pretty_printable.rb +45 -83
- data/lib/types/props/serializable.rb +14 -7
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ac41fea7b5354a514a6c533af5f1e841e99f15005f518dd23eb680e1720b77a6
|
|
4
|
+
data.tar.gz: 6f0a88610b4647b01bdf5b90f6c59b4860fc1a33e188b3ee0db0e6f2fedf4d91
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 60979a79a16f57bea42b4c1fdfa51b35c434d8b8073f45c23210e1302ff8e3ae2d55c65f7cfe1ab93fc960020885107c2658e8f40513e30e6c1522c5198c4c90
|
|
7
|
+
data.tar.gz: 0fb936fe574077ecad1514b54a4ee4144e3581048b323b89042eaa2f4b5c8c95c5a5ef44920602eb709ad36df42a982dc01e4dc2a5717a43f2c15b6d79125c6b
|
|
@@ -1,18 +1,49 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
# typed: true
|
|
3
|
+
require 'pp'
|
|
3
4
|
|
|
4
5
|
module T::Props::PrettyPrintable
|
|
5
6
|
include T::Props::Plugin
|
|
6
7
|
|
|
7
|
-
#
|
|
8
|
+
# Override the PP gem with something that's similar, but gives us a hook to do redaction and customization
|
|
9
|
+
def pretty_print(pp)
|
|
10
|
+
clazz = T.unsafe(T.cast(self, Object).class).decorator
|
|
11
|
+
multiline = pp.is_a?(PP)
|
|
12
|
+
pp.group(1, "<#{clazz.inspect_class_with_decoration(self)}", ">") do
|
|
13
|
+
clazz.all_props.sort.each do |prop|
|
|
14
|
+
pp.breakable
|
|
15
|
+
val = clazz.get(self, prop)
|
|
16
|
+
rules = clazz.prop_rules(prop)
|
|
17
|
+
pp.text("#{prop}=")
|
|
18
|
+
if (custom_inspect = rules[:inspect])
|
|
19
|
+
inspected = if T::Utils.arity(custom_inspect) == 1
|
|
20
|
+
custom_inspect.call(val)
|
|
21
|
+
else
|
|
22
|
+
custom_inspect.call(val, {multiline: multiline})
|
|
23
|
+
end
|
|
24
|
+
pp.text(inspected.nil? ? "nil" : inspected)
|
|
25
|
+
elsif rules[:sensitivity] && !rules[:sensitivity].empty? && !val.nil?
|
|
26
|
+
pp.text("<REDACTED #{rules[:sensitivity].join(', ')}>")
|
|
27
|
+
else
|
|
28
|
+
val.pretty_print(pp)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
clazz.pretty_print_extra(self, pp)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Return a string representation of this object and all of its props in a single line
|
|
8
36
|
def inspect
|
|
9
|
-
|
|
37
|
+
string = +""
|
|
38
|
+
PP.singleline_pp(self, string)
|
|
39
|
+
string
|
|
10
40
|
end
|
|
11
41
|
|
|
12
|
-
#
|
|
13
|
-
# to do redaction
|
|
42
|
+
# Return a pretty string representation of this object and all of its props
|
|
14
43
|
def pretty_inspect
|
|
15
|
-
|
|
44
|
+
string = +""
|
|
45
|
+
PP.pp(self, string)
|
|
46
|
+
string
|
|
16
47
|
end
|
|
17
48
|
|
|
18
49
|
module DecoratorMethods
|
|
@@ -23,85 +54,16 @@ module T::Props::PrettyPrintable
|
|
|
23
54
|
super || key == :inspect
|
|
24
55
|
end
|
|
25
56
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
57
|
+
# Overridable method to specify how the first part of a `pretty_print`d object's class should look like
|
|
58
|
+
# NOTE: This is just to support Stripe's `PrettyPrintableModel` case, and not recommended to be overriden
|
|
59
|
+
sig {params(instance: T::Props::PrettyPrintable).returns(String)}
|
|
60
|
+
def inspect_class_with_decoration(instance)
|
|
61
|
+
T.unsafe(instance).class.to_s
|
|
29
62
|
end
|
|
30
|
-
def inspect_instance(instance, multiline: false, indent: ' ')
|
|
31
|
-
components =
|
|
32
|
-
inspect_instance_components(
|
|
33
|
-
instance,
|
|
34
|
-
multiline: multiline,
|
|
35
|
-
indent: indent
|
|
36
|
-
)
|
|
37
|
-
.reject(&:empty?)
|
|
38
|
-
|
|
39
|
-
# Not using #<> here as that makes pry highlight these objects
|
|
40
|
-
# as if they were all comments, whereas this makes them look
|
|
41
|
-
# like the structured thing they are.
|
|
42
|
-
if multiline
|
|
43
|
-
"#{components[0]}:\n" + T.must(components[1..-1]).join("\n")
|
|
44
|
-
else
|
|
45
|
-
"<#{components.join(' ')}>"
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
sig do
|
|
50
|
-
params(instance: T::Props::PrettyPrintable, multiline: T::Boolean, indent: String)
|
|
51
|
-
.returns(T::Array[String])
|
|
52
|
-
end
|
|
53
|
-
private def inspect_instance_components(instance, multiline:, indent:)
|
|
54
|
-
pretty_props = T.unsafe(self).all_props.map do |prop|
|
|
55
|
-
[prop, inspect_prop_value(instance, prop, multiline: multiline, indent: indent)]
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
joined_props = join_props_with_pretty_values(
|
|
59
|
-
pretty_props,
|
|
60
|
-
multiline: multiline,
|
|
61
|
-
indent: indent
|
|
62
|
-
)
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
sig do
|
|
71
|
-
params(instance: T::Props::PrettyPrintable, prop: Symbol, multiline: T::Boolean, indent: String)
|
|
72
|
-
.returns(String)
|
|
73
|
-
.checked(:never)
|
|
74
|
-
end
|
|
75
|
-
private def inspect_prop_value(instance, prop, multiline:, indent:)
|
|
76
|
-
val = T.unsafe(self).get(instance, prop)
|
|
77
|
-
rules = T.unsafe(self).prop_rules(prop)
|
|
78
|
-
if (custom_inspect = rules[:inspect])
|
|
79
|
-
if T::Utils.arity(custom_inspect) == 1
|
|
80
|
-
custom_inspect.call(val)
|
|
81
|
-
else
|
|
82
|
-
custom_inspect.call(val, {multiline: multiline, indent: indent})
|
|
83
|
-
end
|
|
84
|
-
elsif rules[:sensitivity] && !rules[:sensitivity].empty? && !val.nil?
|
|
85
|
-
"<REDACTED #{rules[:sensitivity].join(', ')}>"
|
|
86
|
-
else
|
|
87
|
-
val.inspect
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
sig do
|
|
92
|
-
params(pretty_kvs: T::Array[[Symbol, String]], multiline: T::Boolean, indent: String)
|
|
93
|
-
.returns(String)
|
|
94
|
-
end
|
|
95
|
-
private def join_props_with_pretty_values(pretty_kvs, multiline:, indent: ' ')
|
|
96
|
-
pairs = pretty_kvs
|
|
97
|
-
.sort_by {|k, _v| k.to_s}
|
|
98
|
-
.map {|k, v| "#{k}=#{v}"}
|
|
99
|
-
|
|
100
|
-
if multiline
|
|
101
|
-
indent + pairs.join("\n#{indent}")
|
|
102
|
-
else
|
|
103
|
-
pairs.join(', ')
|
|
104
|
-
end
|
|
105
|
-
end
|
|
64
|
+
# Overridable method to add anything that is not a prop
|
|
65
|
+
# NOTE: This is to support cases like Serializable's `@_extra_props`, and Stripe's `PrettyPrintableModel#@_deleted`
|
|
66
|
+
sig {params(instance: T::Props::PrettyPrintable, pp: T.any(PrettyPrint, PP::SingleLine)).void}
|
|
67
|
+
def pretty_print_extra(instance, pp); end
|
|
106
68
|
end
|
|
107
69
|
end
|
|
@@ -338,14 +338,21 @@ module T::Props::Serializable::DecoratorMethods
|
|
|
338
338
|
end
|
|
339
339
|
end
|
|
340
340
|
|
|
341
|
-
#
|
|
342
|
-
|
|
341
|
+
# adds to the default result of T::Props::PrettyPrintable
|
|
342
|
+
def pretty_print_extra(instance, pp)
|
|
343
|
+
# This is to maintain backwards compatibility with Stripe's codebase, where only the single line (through `inspect`)
|
|
344
|
+
# version is expected to add anything extra
|
|
345
|
+
return if !pp.is_a?(PP::SingleLine)
|
|
343
346
|
if (extra_props = extra_props(instance)) && !extra_props.empty?
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
347
|
+
pp.breakable
|
|
348
|
+
pp.text("@_extra_props=")
|
|
349
|
+
pp.group(1, "<", ">") do
|
|
350
|
+
extra_props.each_with_index do |(prop, value), i|
|
|
351
|
+
pp.breakable unless i.zero?
|
|
352
|
+
pp.text("#{prop}=")
|
|
353
|
+
value.pretty_print(pp)
|
|
354
|
+
end
|
|
355
|
+
end
|
|
349
356
|
end
|
|
350
357
|
end
|
|
351
358
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sorbet-runtime
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.10590
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stripe
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-12-
|
|
11
|
+
date: 2022-12-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|