Module: Typed::Coercion
- Extended by:
- T::Sig
- Defined in:
- lib/typed/coercion.rb,
lib/typed/coercion/coercer.rb,
lib/typed/coercion/date_coercer.rb,
lib/typed/coercion/enum_coercer.rb,
lib/typed/coercion/float_coercer.rb,
lib/typed/coercion/coercion_error.rb,
lib/typed/coercion/string_coercer.rb,
lib/typed/coercion/struct_coercer.rb,
lib/typed/coercion/symbol_coercer.rb,
lib/typed/coercion/boolean_coercer.rb,
lib/typed/coercion/integer_coercer.rb,
lib/typed/coercion/coercer_registry.rb,
lib/typed/coercion/date_time_coercer.rb,
lib/typed/coercion/typed_hash_coercer.rb,
lib/typed/coercion/typed_array_coercer.rb,
lib/typed/coercion/coercion_not_supported_error.rb
Defined Under Namespace
Classes: BooleanCoercer, Coercer, CoercerRegistry, CoercionError, CoercionNotSupportedError, DateCoercer, DateTimeCoercer, EnumCoercer, FloatCoercer, IntegerCoercer, StringCoercer, StructCoercer, SymbolCoercer, TypedArrayCoercer, TypedHashCoercer
Class Method Summary
collapse
Class Method Details
.coerce(type:, value:) ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/typed/coercion.rb', line 13
def self.coerce(type:, value:)
coercer = CoercerRegistry.instance.select_coercer_by(type:)
return Failure.new(CoercionNotSupportedError.new(type:)) unless coercer
coercer.new.coerce(type:, value:)
end
|
.register_coercer(coercer) ⇒ Object
8
9
10
|
# File 'lib/typed/coercion.rb', line 8
def self.register_coercer(coercer)
CoercerRegistry.instance.register(coercer)
end
|