sorbet-runtime 0.5.10575 → 0.5.10576
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/types/props/pretty_printable.rb +86 -39
- data/lib/types/props/serializable.rb +7 -11
- 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: 57e2d9879044c87f4a728718f0d455a3e91bd52197e21eb151b31341190c20f0
|
4
|
+
data.tar.gz: 7b9566557f8b1105d8cdaf01f7875435a3c3ba28dcc08b926ee52d71c7932f4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60fcb254c9aa69b182f31d1e29475ce1cde419d0ffc631774e833993e10457f61b65c508bd89ce37b34369671435370acb33f3686a6d500deabd8d900e7849a3
|
7
|
+
data.tar.gz: c4df33cfcafab1ac05720a2f361b801ce5ea58a845295261b9faa705ebba22fb63ed7416a94d976e7fa4c7ba10011baa16995510beca9df8c6d80344f3ce68e7
|
@@ -1,52 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
# typed: true
|
3
|
-
require 'pp'
|
4
3
|
|
5
4
|
module T::Props::PrettyPrintable
|
6
5
|
include T::Props::Plugin
|
7
6
|
|
8
|
-
#
|
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, "<#{T.unsafe(self).class}", ">") 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
|
-
# Overridable method to add anything that is not a prop
|
36
|
-
def pretty_print_extra(instance, pp); end
|
37
|
-
|
38
|
-
# Return a string representation of this object and all of its props in a single line
|
7
|
+
# Return a string representation of this object and all of its props
|
39
8
|
def inspect
|
40
|
-
|
41
|
-
PP.singleline_pp(self, string)
|
42
|
-
string
|
9
|
+
T.unsafe(T.cast(self, Object).class).decorator.inspect_instance(self)
|
43
10
|
end
|
44
11
|
|
45
|
-
#
|
12
|
+
# Override the PP gem with something that's similar, but gives us a hook
|
13
|
+
# to do redaction
|
46
14
|
def pretty_inspect
|
47
|
-
|
48
|
-
PP.pp(self, string)
|
49
|
-
string
|
15
|
+
T.unsafe(T.cast(self, Object).class).decorator.inspect_instance(self, multiline: true)
|
50
16
|
end
|
51
17
|
|
52
18
|
module DecoratorMethods
|
@@ -56,5 +22,86 @@ module T::Props::PrettyPrintable
|
|
56
22
|
def valid_rule_key?(key)
|
57
23
|
super || key == :inspect
|
58
24
|
end
|
25
|
+
|
26
|
+
sig do
|
27
|
+
params(instance: T::Props::PrettyPrintable, multiline: T::Boolean, indent: String)
|
28
|
+
.returns(String)
|
29
|
+
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
|
+
|
64
|
+
[
|
65
|
+
T.unsafe(self).decorated_class.to_s,
|
66
|
+
joined_props,
|
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
|
59
106
|
end
|
60
107
|
end
|
@@ -338,18 +338,14 @@ module T::Props::Serializable::DecoratorMethods
|
|
338
338
|
end
|
339
339
|
end
|
340
340
|
|
341
|
-
#
|
342
|
-
def
|
341
|
+
# overrides T::Props::PrettyPrintable
|
342
|
+
private def inspect_instance_components(instance, multiline:, indent:)
|
343
343
|
if (extra_props = extra_props(instance)) && !extra_props.empty?
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
pp.text("#{prop}=")
|
350
|
-
value.pretty_print(pp)
|
351
|
-
end
|
352
|
-
end
|
344
|
+
pretty_kvs = extra_props.map {|k, v| [k.to_sym, v.inspect]}
|
345
|
+
extra = join_props_with_pretty_values(pretty_kvs, multiline: false)
|
346
|
+
super + ["@_extra_props=<#{extra}>"]
|
347
|
+
else
|
348
|
+
super
|
353
349
|
end
|
354
350
|
end
|
355
351
|
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.10576
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|