Built-in Types
Built-in types are grouped under 6 categories:
nominal- base type definitions with a primitive class and optionsstrict- constrained types with a primitive type check applied to inputcoercible- types with constructors using kernel coercionsparams- types with constructors performing non-strict coercions specific to HTTP parametersjson- types with constructors performing non-strict coercions specific to JSONmaybe- types accepting either nil or a specific primitive type
Categories
Assuming you included Dry::Types (see instructions) in a module called Types:
Nominal types:
Types::Nominal::AnyTypes::Nominal::NilTypes::Nominal::SymbolTypes::Nominal::ClassTypes::Nominal::TrueTypes::Nominal::FalseTypes::Nominal::BoolTypes::Nominal::IntegerTypes::Nominal::FloatTypes::Nominal::DecimalTypes::Nominal::StringTypes::Nominal::DateTypes::Nominal::DateTimeTypes::Nominal::TimeTypes::Nominal::ArrayTypes::Nominal::Hash
Stricttypes will raise an error if passed a value of the wrong type:Types::Strict::NilTypes::Strict::SymbolTypes::Strict::ClassTypes::Strict::TrueTypes::Strict::FalseTypes::Strict::BoolTypes::Strict::IntegerTypes::Strict::FloatTypes::Strict::DecimalTypes::Strict::StringTypes::Strict::DateTypes::Strict::DateTimeTypes::Strict::TimeTypes::Strict::ArrayTypes::Strict::Hash
All types in the
strictcategory are constrained by a type-check that is applied to make sure that the input is an instance of the primitive:
Types::Strict::Integer[1] # => 1
Types::Strict::Integer['1'] # => raises Dry::Types::ConstraintError
Coercibletypes will attempt to cast values to the correct class using kernel coercion methods:Types::Coercible::StringTypes::Coercible::SymbolTypes::Coercible::IntegerTypes::Coercible::FloatTypes::Coercible::DecimalTypes::Coercible::ArrayTypes::Coercible::Hash
Types suitable for
Paramsparam processing with coercions:Types::Params::NilTypes::Params::DateTypes::Params::DateTimeTypes::Params::TimeTypes::Params::TrueTypes::Params::FalseTypes::Params::BoolTypes::Params::IntegerTypes::Params::FloatTypes::Params::DecimalTypes::Params::ArrayTypes::Params::Hash
Types suitable for
JSONprocessing with coercions:Types::JSON::NilTypes::JSON::SymbolTypes::JSON::DateTypes::JSON::DateTimeTypes::JSON::TimeTypes::JSON::DecimalTypes::JSON::ArrayTypes::JSON::Hash
Maybestrict types:Types::Maybe::Strict::ClassTypes::Maybe::Strict::StringTypes::Maybe::Strict::SymbolTypes::Maybe::Strict::TrueTypes::Maybe::Strict::FalseTypes::Maybe::Strict::IntegerTypes::Maybe::Strict::FloatTypes::Maybe::Strict::DecimalTypes::Maybe::Strict::DateTypes::Maybe::Strict::DateTimeTypes::Maybe::Strict::TimeTypes::Maybe::Strict::ArrayTypes::Maybe::Strict::Hash
Maybecoercible types:Types::Maybe::Coercible::StringTypes::Maybe::Coercible::IntegerTypes::Maybe::Coercible::FloatTypes::Maybe::Coercible::DecimalTypes::Maybe::Coercible::ArrayTypes::Maybe::Coercible::Hash
Maybetypes are not available by default - they must be loaded usingDry::Types.load_extensions(:maybe). See Maybe extension for more information.