Skip to content

Commit 281b37a

Browse files
committed
Update enumerizable_enum.rb
1 parent 10ca72e commit 281b37a

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

lib/zaxcel/sorbet/enumerizable_enum.rb

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,33 @@
1818
# value_class: Category,
1919
# )
2020
# ```
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
2526

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
2930

30-
class_methods do
31-
extend T::Sig
31+
class_methods do
32+
extend T::Sig
3233

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
3940

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
4243

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
4648
end
4749
end
4850
end

0 commit comments

Comments
 (0)