sorbet-runtime 0.4.4972 → 0.4.4997
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/sorbet-runtime.rb +1 -1
- data/lib/types/enum.rb +20 -11
- data/lib/types/props/decorator.rb +1 -7
- data/lib/types/props/utils.rb +3 -9
- data/lib/types/types/{opus_enum.rb → t_enum.rb} +3 -3
- data/lib/types/utils.rb +2 -4
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 56172454398482546a7fab9463bf8e293f3edcb551e324148a030da45d9cce04
|
|
4
|
+
data.tar.gz: 20bb28765140390c4616c0d6dddf118588a360fe8c4a2b8b8b5c07d044c7e37c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4b161f44c8fff272feec1721fd94e0afb3701e1cd34daca9c42baf9116cc88c9e9483398ddc7332b3eaa5d31b1b8b4a3afa777f481eb860e590aea82421f5d20
|
|
7
|
+
data.tar.gz: a47d57c995bea22fcdd2d8db826c9977d739f2d322c6acf2204c29147df46aa2ecb33c27daf45d37a0835e8962a28ebea747a334f4fbf0c548bcf77072d4d7a6
|
data/lib/sorbet-runtime.rb
CHANGED
|
@@ -45,7 +45,7 @@ require_relative 'types/types/proc'
|
|
|
45
45
|
require_relative 'types/types/attached_class'
|
|
46
46
|
require_relative 'types/types/self_type'
|
|
47
47
|
require_relative 'types/types/simple'
|
|
48
|
-
require_relative 'types/types/
|
|
48
|
+
require_relative 'types/types/t_enum'
|
|
49
49
|
require_relative 'types/types/type_parameter'
|
|
50
50
|
require_relative 'types/types/typed_array'
|
|
51
51
|
require_relative 'types/types/typed_enumerator'
|
data/lib/types/enum.rb
CHANGED
|
@@ -12,17 +12,17 @@
|
|
|
12
12
|
# @example Declaring an Enum:
|
|
13
13
|
# class Suit < T::Enum
|
|
14
14
|
# enums do
|
|
15
|
-
# CLUB =
|
|
16
|
-
# SPADE =
|
|
17
|
-
# DIAMOND =
|
|
18
|
-
# HEART =
|
|
15
|
+
# CLUB = new
|
|
16
|
+
# SPADE = new
|
|
17
|
+
# DIAMOND = new
|
|
18
|
+
# HEART = new
|
|
19
19
|
# end
|
|
20
20
|
# end
|
|
21
21
|
#
|
|
22
22
|
# @example Custom serialization value:
|
|
23
23
|
# class Status < T::Enum
|
|
24
24
|
# enums do
|
|
25
|
-
# READY =
|
|
25
|
+
# READY = new('rdy')
|
|
26
26
|
# ...
|
|
27
27
|
# end
|
|
28
28
|
# end
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
# Suit::SPADE
|
|
32
32
|
#
|
|
33
33
|
# @example Converting from serialized value to enum instance:
|
|
34
|
-
# Suit.
|
|
34
|
+
# Suit.deserialize('club') == Suit::CLUB
|
|
35
35
|
#
|
|
36
36
|
# @example Using enums in type signatures:
|
|
37
37
|
# sig {params(suit: Suit).returns(Boolean)}
|
|
@@ -57,6 +57,19 @@ class T::Enum
|
|
|
57
57
|
@values
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
+
# Convert from serialized value to enum instance
|
|
61
|
+
#
|
|
62
|
+
# Note: It would have been nice to make this method final before people started overriding it.
|
|
63
|
+
# Note: Failed CriticalMethodsNoRuntimeTypingTest
|
|
64
|
+
sig {params(serialized_val: SerializedVal).returns(T.nilable(T.experimental_attached_class)).checked(:never)}
|
|
65
|
+
def self.try_deserialize(serialized_val)
|
|
66
|
+
if @mapping.nil?
|
|
67
|
+
raise "Attempting to access serialization map of #{self.class} before it has been initialized." \
|
|
68
|
+
" Enums are not initialized until the 'enums do' block they are defined in has finished running."
|
|
69
|
+
end
|
|
70
|
+
@mapping[serialized_val]
|
|
71
|
+
end
|
|
72
|
+
|
|
60
73
|
# Convert from serialized value to enum instance.
|
|
61
74
|
#
|
|
62
75
|
# Note: It would have been nice to make this method final before people started overriding it.
|
|
@@ -66,11 +79,7 @@ class T::Enum
|
|
|
66
79
|
# @raise [KeyError] if serialized value does not match any instance.
|
|
67
80
|
sig {overridable.params(serialized_val: SerializedVal).returns(T.experimental_attached_class).checked(:never)}
|
|
68
81
|
def self.from_serialized(serialized_val)
|
|
69
|
-
|
|
70
|
-
raise "Attempting to access serialization map of #{self.class} before it has been initialized." \
|
|
71
|
-
" Enums are not initialized until the 'enums do' block they are defined in has finished running."
|
|
72
|
-
end
|
|
73
|
-
res = @mapping[serialized_val]
|
|
82
|
+
res = try_deserialize(serialized_val)
|
|
74
83
|
if res.nil?
|
|
75
84
|
raise KeyError.new("Enum #{self} key not found: #{serialized_val.inspect}")
|
|
76
85
|
end
|
|
@@ -552,7 +552,7 @@ class T::Props::Decorator
|
|
|
552
552
|
nil
|
|
553
553
|
end
|
|
554
554
|
|
|
555
|
-
# returns the type of the hash key, or nil. Any CustomType could be a key, but we only expect
|
|
555
|
+
# returns the type of the hash key, or nil. Any CustomType could be a key, but we only expect T::Enum right now.
|
|
556
556
|
sig do
|
|
557
557
|
params(type: PropType)
|
|
558
558
|
.returns(T.nilable(Module))
|
|
@@ -571,12 +571,6 @@ class T::Props::Decorator
|
|
|
571
571
|
|
|
572
572
|
# From T::Props::Utils.deep_clone_object, plus String
|
|
573
573
|
TYPES_NOT_NEEDING_CLONE = [TrueClass, FalseClass, NilClass, Symbol, String, Numeric]
|
|
574
|
-
if defined?(Opus) && defined?(Opus::Enum)
|
|
575
|
-
TYPES_NOT_NEEDING_CLONE << Opus::Enum
|
|
576
|
-
end
|
|
577
|
-
if defined?(T::Enum)
|
|
578
|
-
TYPES_NOT_NEEDING_CLONE << T::Enum
|
|
579
|
-
end
|
|
580
574
|
|
|
581
575
|
sig {params(type: PropType).returns(T::Boolean)}
|
|
582
576
|
private def shallow_clone_ok(type)
|
data/lib/types/props/utils.rb
CHANGED
|
@@ -23,16 +23,10 @@ module T::Props::Utils
|
|
|
23
23
|
h
|
|
24
24
|
when Regexp
|
|
25
25
|
what.dup
|
|
26
|
+
when T::Enum
|
|
27
|
+
what
|
|
26
28
|
else
|
|
27
|
-
|
|
28
|
-
# being defined.
|
|
29
|
-
if defined?(Opus) && defined?(Opus::Enum) && what.class == Opus::Enum
|
|
30
|
-
what
|
|
31
|
-
elsif defined?(T::Enum) && what.class == T::Enum
|
|
32
|
-
what
|
|
33
|
-
else
|
|
34
|
-
what.clone
|
|
35
|
-
end
|
|
29
|
+
what.clone
|
|
36
30
|
end
|
|
37
31
|
freeze ? result.freeze : result
|
|
38
32
|
end
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
# typed: true
|
|
3
3
|
|
|
4
4
|
module T::Types
|
|
5
|
-
# Validates that an object is equal to another
|
|
6
|
-
class
|
|
5
|
+
# Validates that an object is equal to another T::Enum singleton value.
|
|
6
|
+
class TEnum < Base
|
|
7
7
|
attr_reader :val
|
|
8
8
|
|
|
9
9
|
def initialize(val)
|
|
@@ -23,7 +23,7 @@ module T::Types
|
|
|
23
23
|
# @override Base
|
|
24
24
|
private def subtype_of_single?(other)
|
|
25
25
|
case other
|
|
26
|
-
when
|
|
26
|
+
when TEnum
|
|
27
27
|
@val == other.val
|
|
28
28
|
else
|
|
29
29
|
false
|
data/lib/types/utils.rb
CHANGED
|
@@ -28,10 +28,8 @@ module T::Utils
|
|
|
28
28
|
T::Types::FixedHash.new(val) # rubocop:disable PrisonGuard/UseOpusTypesShortcut
|
|
29
29
|
elsif val.is_a?(T::Private::Methods::DeclBuilder)
|
|
30
30
|
T::Private::Methods.finalize_proc(val.decl)
|
|
31
|
-
elsif
|
|
32
|
-
T::Types::
|
|
33
|
-
elsif defined?(::T::Enum) && val.is_a?(::T::Enum)
|
|
34
|
-
T::Types::OpusEnum.new(val) # rubocop:disable PrisonGuard/UseOpusTypesShortcut
|
|
31
|
+
elsif val.is_a?(::T::Enum)
|
|
32
|
+
T::Types::TEnum.new(val) # rubocop:disable PrisonGuard/UseOpusTypesShortcut
|
|
35
33
|
elsif val.is_a?(::String)
|
|
36
34
|
raise "Invalid String literal for type constraint. Must be an #{T::Types::Base}, a " \
|
|
37
35
|
"class/module, or an array. Got a String with value `#{val}`."
|
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.4.
|
|
4
|
+
version: 0.4.4997
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stripe
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-11-
|
|
11
|
+
date: 2019-11-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|
|
@@ -127,10 +127,10 @@ files:
|
|
|
127
127
|
- lib/types/types/fixed_hash.rb
|
|
128
128
|
- lib/types/types/intersection.rb
|
|
129
129
|
- lib/types/types/noreturn.rb
|
|
130
|
-
- lib/types/types/opus_enum.rb
|
|
131
130
|
- lib/types/types/proc.rb
|
|
132
131
|
- lib/types/types/self_type.rb
|
|
133
132
|
- lib/types/types/simple.rb
|
|
133
|
+
- lib/types/types/t_enum.rb
|
|
134
134
|
- lib/types/types/type_member.rb
|
|
135
135
|
- lib/types/types/type_parameter.rb
|
|
136
136
|
- lib/types/types/type_template.rb
|