Sha256: 5641ab270750f36dfc2d9ad17e3f7c6a54a5de3330b20e3887c7b5b19a7824d7
Contents?: true
Size: 867 Bytes
Versions: 4
Compression:
Stored size: 867 Bytes
Contents
# typed: strict require "singleton" module Typed module Coercion class CoercerRegistry extend T::Sig include Singleton Registry = T.type_alias { T::Array[T.class_of(Coercer)] } DEFAULT_COERCERS = T.let([StringCoercer, IntegerCoercer, FloatCoercer, StructCoercer], Registry) sig { void } def initialize @available = T.let(DEFAULT_COERCERS.clone, Registry) end sig { params(coercer: T.class_of(Coercer)).void } def register(coercer) @available.prepend(coercer) end sig { void } def reset! @available = DEFAULT_COERCERS.clone end sig { params(type: T::Class[T.anything]).returns(T.nilable(T.class_of(Coercer))) } def select_coercer_by(type:) @available.find { |coercer| coercer.new.used_for_type?(type) } end end end end
Version data entries
4 entries across 4 versions & 1 rubygems