|
18 | 18 | # value_class: Category, |
19 | 19 | # ) |
20 | 20 | # ``` |
21 | | -module Sorbet::EnumerizableEnum |
22 | | - extend ActiveSupport::Concern |
23 | | - extend T::Sig |
24 | | - extend T::Generic |
| 21 | +class Sorbet |
| 22 | + module EnumerizableEnum |
| 23 | + extend ActiveSupport::Concern |
| 24 | + extend T::Sig |
| 25 | + extend T::Generic |
25 | 26 |
|
26 | | - # Enumerize requires that `value` on an instance of the `value_class` returns the enum's underlying value. |
27 | | - sig { returns(Symbol) } |
28 | | - def value = T.bind(self, T::Enum).serialize |
| 27 | + # Enumerize requires that `value` on an instance of the `value_class` returns the enum's underlying value. |
| 28 | + sig { returns(Symbol) } |
| 29 | + def value = T.bind(self, T::Enum).serialize |
29 | 30 |
|
30 | | - class_methods do |
31 | | - extend T::Sig |
| 31 | + class_methods do |
| 32 | + extend T::Sig |
32 | 33 |
|
33 | | - # Monkey patch new to call `new` on `T::Enum` if a single value is passed in, otherwise call `deserialize` on the |
34 | | - # on the enum class. Enumerize calls `new` on the value class with two args; the second of which is the underlying |
35 | | - # value. |
36 | | - sig { params(args: T.untyped).returns(T.untyped) } |
37 | | - def new(*args) |
38 | | - return super if args.length == 1 |
| 34 | + # Monkey patch new to call `new` on `T::Enum` if a single value is passed in, otherwise call `deserialize` on the |
| 35 | + # on the enum class. Enumerize calls `new` on the value class with two args; the second of which is the underlying |
| 36 | + # value. |
| 37 | + sig { params(args: T.untyped).returns(T.untyped) } |
| 38 | + def new(*args) |
| 39 | + return super if args.length == 1 |
39 | 40 |
|
40 | | - T.bind(self, T.class_of(T::Enum)).deserialize(args[1].to_sym) |
41 | | - end |
| 41 | + T.bind(self, T.class_of(T::Enum)).deserialize(args[1].to_sym) |
| 42 | + end |
42 | 43 |
|
43 | | - sig { returns(T::Array[Symbol]) } |
44 | | - def enumerize_values |
45 | | - T.bind(self, T.class_of(T::Enum)).values.map(&:serialize) |
| 44 | + sig { returns(T::Array[Symbol]) } |
| 45 | + def enumerize_values |
| 46 | + T.bind(self, T.class_of(T::Enum)).values.map(&:serialize) |
| 47 | + end |
46 | 48 | end |
47 | 49 | end |
48 | 50 | end |
0 commit comments