Class: Typed::Coercion::EnumCoercer
- Extended by:
- T::Generic
- Defined in:
- lib/typed/coercion/enum_coercer.rb
Constant Summary collapse
- Target =
type_member { {fixed: T::Enum} }
Instance Method Summary collapse
Instance Method Details
#coerce(type:, value:) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/typed/coercion/enum_coercer.rb', line 18 def coerce(type:, value:) return Failure.new(CoercionError.new("Field type must inherit from T::Enum for Enum coercion.")) unless used_for_type?(type) Success.new(T.cast(type, T::Types::Simple).raw_type.from_serialized(value)) rescue KeyError => e Failure.new(CoercionError.new(e.)) end |