sorbet-runtime 0.5.6332 → 0.5.6349
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/configuration.rb +16 -0
- data/lib/types/private/final.rb +0 -1
- data/lib/types/private/methods/_methods.rb +35 -24
- data/lib/types/props/decorator.rb +5 -2
- 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: 37e5c18902b6bf05fda832dcfae31a46dd3ad7c454c7741f7003924c70e351fc
|
4
|
+
data.tar.gz: fba7a016bdbc64626802d5ccfdc9cf18ac382936ac7c98dc3bb62b610754a8e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4754a24ac572c182cb80f76c0505e02e61af830e2585cf73b464eba30fe24fc51c9ffeaa2b6ef1ff31a5d3b97e1c70e2d52de6398e924262cbae94e9408334ab
|
7
|
+
data.tar.gz: e7120e72312db83159fdde80db0ca357bf526e69fd7d97d5327623b5d3cc1f0c6d76753c25c1fd8ec52542b087a7e17db94e65a4de8c920efbbcff785cd4cdd2
|
data/lib/types/configuration.rb
CHANGED
@@ -433,6 +433,22 @@ module T::Configuration
|
|
433
433
|
@sensitivity_and_pii_handler
|
434
434
|
end
|
435
435
|
|
436
|
+
@redaction_handler = nil
|
437
|
+
# Set to a redaction handling function. This will be called when the
|
438
|
+
# `_redacted` version of a prop reader is used. By default this is set to
|
439
|
+
# `nil` and will raise an exception when the redacted version of a prop is
|
440
|
+
# accessed.
|
441
|
+
#
|
442
|
+
# @param [Lambda, Proc, nil] value Proc that converts a value into its
|
443
|
+
# redacted version according to the spec passed as the second argument.
|
444
|
+
def self.redaction_handler=(handler)
|
445
|
+
@redaction_handler = handler
|
446
|
+
end
|
447
|
+
|
448
|
+
def self.redaction_handler
|
449
|
+
@redaction_handler
|
450
|
+
end
|
451
|
+
|
436
452
|
# Set to a function which can get the 'owner' of a class. This is
|
437
453
|
# used in reporting deserialization errors
|
438
454
|
#
|
data/lib/types/private/final.rb
CHANGED
@@ -37,7 +37,6 @@ module T::Private::Final
|
|
37
37
|
mod.extend(mod.is_a?(Class) ? NoInherit : NoIncludeExtend)
|
38
38
|
mark_as_final_module(mod)
|
39
39
|
mark_as_final_module(mod.singleton_class)
|
40
|
-
T::Private::Methods.add_module_with_final(mod)
|
41
40
|
T::Private::Methods.install_hooks(mod)
|
42
41
|
end
|
43
42
|
|
@@ -99,16 +99,10 @@ module T::Private::Methods
|
|
99
99
|
# when target includes a module with instance methods source_method_names, ensure there is zero intersection between
|
100
100
|
# the final instance methods of target and source_method_names. so, for every m in source_method_names, check if there
|
101
101
|
# is already a method defined on one of target_ancestors with the same name that is final.
|
102
|
+
#
|
103
|
+
# we assume that source_method_names has already been filtered to only include method
|
104
|
+
# names that were declared final at one point.
|
102
105
|
def self._check_final_ancestors(target, target_ancestors, source_method_names)
|
103
|
-
if !module_with_final?(target)
|
104
|
-
return
|
105
|
-
end
|
106
|
-
source_method_names.filter! do |method_name|
|
107
|
-
was_ever_final?(method_name)
|
108
|
-
end
|
109
|
-
if source_method_names.empty?
|
110
|
-
return
|
111
|
-
end
|
112
106
|
# use reverse_each to check farther-up ancestors first, for better error messages. we could avoid this if we were on
|
113
107
|
# the version of ruby that adds the optional argument to method_defined? that allows you to exclude ancestors.
|
114
108
|
target_ancestors.reverse_each do |ancestor|
|
@@ -187,11 +181,14 @@ module T::Private::Methods
|
|
187
181
|
if T::Private::Final.final_module?(mod) && (current_declaration.nil? || !current_declaration.final)
|
188
182
|
raise "#{mod} was declared as final but its method `#{method_name}` was not declared as final"
|
189
183
|
end
|
190
|
-
|
184
|
+
# Don't compute mod.ancestors if we don't need to bother checking final-ness.
|
185
|
+
if was_ever_final?(method_name) && module_with_final?(mod)
|
186
|
+
_check_final_ancestors(mod, mod.ancestors, [method_name])
|
187
|
+
# We need to fetch the active declaration again, as _check_final_ancestors
|
188
|
+
# may have reset it (see the comment in that method for details).
|
189
|
+
current_declaration = T::Private::DeclState.current.active_declaration
|
190
|
+
end
|
191
191
|
|
192
|
-
# We need to fetch the active declaration again, as _check_final_ancestors
|
193
|
-
# may have reset it (see the comment in that method for details).
|
194
|
-
current_declaration = T::Private::DeclState.current.active_declaration
|
195
192
|
if current_declaration.nil?
|
196
193
|
return
|
197
194
|
end
|
@@ -213,9 +210,9 @@ module T::Private::Methods
|
|
213
210
|
# which is called only on the *first* invocation.
|
214
211
|
# This wrapper is very slow, so it will subsequently re-wrap with a much faster wrapper
|
215
212
|
# (or unwrap back to the original method).
|
216
|
-
|
213
|
+
key = method_owner_and_name_to_key(mod, method_name)
|
217
214
|
T::Private::ClassUtils.replace_method(mod, method_name) do |*args, &blk|
|
218
|
-
method_sig = T::Private::Methods.
|
215
|
+
method_sig = T::Private::Methods.maybe_run_sig_block_for_key(key)
|
219
216
|
method_sig ||= T::Private::Methods._handle_missing_method_signature(
|
220
217
|
self,
|
221
218
|
original_method,
|
@@ -242,8 +239,6 @@ module T::Private::Methods
|
|
242
239
|
end
|
243
240
|
end
|
244
241
|
|
245
|
-
new_method = mod.instance_method(method_name)
|
246
|
-
key = method_to_key(new_method)
|
247
242
|
@sig_wrappers[key] = sig_block
|
248
243
|
if current_declaration.final
|
249
244
|
add_final_method(key)
|
@@ -382,7 +377,8 @@ module T::Private::Methods
|
|
382
377
|
maybe_run_sig_block_for_key(method_to_key(method))
|
383
378
|
end
|
384
379
|
|
385
|
-
|
380
|
+
# Only public so that it can be accessed in the closure for _on_method_added
|
381
|
+
def self.maybe_run_sig_block_for_key(key)
|
386
382
|
run_sig_block_for_key(key) if has_sig_block_for_key(key)
|
387
383
|
end
|
388
384
|
|
@@ -426,15 +422,30 @@ module T::Private::Methods
|
|
426
422
|
|
427
423
|
# the module target is adding the methods from the module source to itself. we need to check that for all instance
|
428
424
|
# methods M on source, M is not defined on any of target's ancestors.
|
429
|
-
def self._hook_impl(target,
|
430
|
-
|
425
|
+
def self._hook_impl(target, singleton_class, source)
|
426
|
+
target_was_final = module_with_final?(target)
|
427
|
+
if !target_was_final && !module_with_final?(source)
|
431
428
|
return
|
432
429
|
end
|
433
430
|
# we do not need to call add_was_ever_final here, because we have already marked
|
434
431
|
# any such methods when source was originally defined.
|
435
432
|
add_module_with_final(target)
|
436
433
|
install_hooks(target)
|
437
|
-
|
434
|
+
|
435
|
+
if !target_was_final
|
436
|
+
return
|
437
|
+
end
|
438
|
+
|
439
|
+
methods = source.instance_methods
|
440
|
+
methods.select! do |method_name|
|
441
|
+
was_ever_final?(method_name)
|
442
|
+
end
|
443
|
+
if methods.empty?
|
444
|
+
return
|
445
|
+
end
|
446
|
+
|
447
|
+
target_ancestors = singleton_class ? target.singleton_class.ancestors : target.ancestors
|
448
|
+
_check_final_ancestors(target, target_ancestors - source.ancestors, methods)
|
438
449
|
end
|
439
450
|
|
440
451
|
def self.set_final_checks_on_hooks(enable)
|
@@ -448,15 +459,15 @@ module T::Private::Methods
|
|
448
459
|
else
|
449
460
|
old_included = T::Private::ClassUtils.replace_method(Module, :included) do |arg|
|
450
461
|
old_included.bind(self).call(arg)
|
451
|
-
::T::Private::Methods._hook_impl(arg,
|
462
|
+
::T::Private::Methods._hook_impl(arg, false, self)
|
452
463
|
end
|
453
464
|
old_extended = T::Private::ClassUtils.replace_method(Module, :extended) do |arg|
|
454
465
|
old_extended.bind(self).call(arg)
|
455
|
-
::T::Private::Methods._hook_impl(arg,
|
466
|
+
::T::Private::Methods._hook_impl(arg, true, self)
|
456
467
|
end
|
457
468
|
old_inherited = T::Private::ClassUtils.replace_method(Class, :inherited) do |arg|
|
458
469
|
old_inherited.bind(self).call(arg)
|
459
|
-
::T::Private::Methods._hook_impl(arg,
|
470
|
+
::T::Private::Methods._hook_impl(arg, false, self)
|
460
471
|
end
|
461
472
|
@old_hooks = [old_included, old_extended, old_inherited]
|
462
473
|
end
|
@@ -449,8 +449,11 @@ class T::Props::Decorator
|
|
449
449
|
|
450
450
|
@class.send(:define_method, redacted_method) do
|
451
451
|
value = self.public_send(prop_name)
|
452
|
-
|
453
|
-
|
452
|
+
handler = T::Configuration.redaction_handler
|
453
|
+
if !handler
|
454
|
+
raise "Using `redaction:` on a prop requires specifying `T::Configuration.redaction_handler`"
|
455
|
+
end
|
456
|
+
handler.call(value, redaction)
|
454
457
|
end
|
455
458
|
end
|
456
459
|
|
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.6349
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stripe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|