Module: Dry

Defined in:
lib/dry/types.rb,
lib/dry/types/any.rb,
lib/dry/types/lax.rb,
lib/dry/types/map.rb,
lib/dry/types/sum.rb,
lib/dry/types/core.rb,
lib/dry/types/enum.rb,
lib/dry/types/hash.rb,
lib/dry/types/json.rb,
lib/dry/types/meta.rb,
lib/dry/types/type.rb,
lib/dry/types/array.rb,
lib/dry/types/errors.rb,
lib/dry/types/module.rb,
lib/dry/types/params.rb,
lib/dry/types/result.rb,
lib/dry/types/schema.rb,
lib/dry/types/builder.rb,
lib/dry/types/default.rb,
lib/dry/types/nominal.rb,
lib/dry/types/options.rb,
lib/dry/types/printer.rb,
lib/dry/types/version.rb,
lib/dry/types/compiler.rb,
lib/dry/types/coercions.rb,
lib/dry/types/container.rb,
lib/dry/types/decorator.rb,
lib/dry/types/inflector.rb,
lib/dry/types/printable.rb,
lib/dry/types/schema/key.rb,
lib/dry/types/composition.rb,
lib/dry/types/constrained.rb,
lib/dry/types/constraints.rb,
lib/dry/types/constructor.rb,
lib/dry/types/implication.rb,
lib/dry/types/array/member.rb,
lib/dry/types/fn_container.rb,
lib/dry/types/intersection.rb,
lib/dry/types/coercions/json.rb,
lib/dry/types/builder_methods.rb,
lib/dry/types/coercions/params.rb,
lib/dry/types/extensions/maybe.rb,
lib/dry/types/hash/constructor.rb,
lib/dry/types/array/constructor.rb,
lib/dry/types/extensions/monads.rb,
lib/dry/types/predicate_inferrer.rb,
lib/dry/types/predicate_registry.rb,
lib/dry/types/primitive_inferrer.rb,
lib/dry/types/constructor/wrapper.rb,
lib/dry/types/printer/composition.rb,
lib/dry/types/constructor/function.rb,
lib/dry/types/constrained/coercible.rb

Overview

Main library namespace

Defined Under Namespace

Modules: Types

Class Method Summary collapse

Class Method Details

.Types(*namespaces, default: Types::Undefined, **aliases) ⇒ Dry::Types::Module

Export registered types as a module with constants

Examples:

no options


module Types
  # imports all types as constants, uses modules for namespaces
  include Dry.Types()
end
# strict types are exported by default
Types::Integer
# => #<Dry::Types[Constrained<Nominal<Integer> rule=[type?(Integer)]>]>
Types::Nominal::Integer
# => #<Dry::Types[Nominal<Integer>]>

changing default types


module Types
  include Dry.Types(default: :nominal)
end
Types::Integer
# => #<Dry::Types[Nominal<Integer>]>

cherry-picking namespaces


module Types
  include Dry.Types(:strict, :coercible)
end
# cherry-picking discards default types,
# provide the :default option along with the list of
# namespaces if you want the to be exported
Types.constants # => [:Coercible, :Strict]

custom names

module Types
  include Dry.Types(coercible: :Kernel)
end
Types::Kernel::Integer
# => #<Dry::Types[Constructor<Nominal<Integer> fn=Kernel.Integer>]>

Parameters:

  • namespaces (Array<Symbol>)

    List of type namespaces to export

  • default (Symbol) (defaults to: Types::Undefined)

    Default namespace to export

  • aliases (Hash{Symbol => Symbol})

    Optional renamings, like strict: :Draconian

Returns:

See Also:



253
254
255
# File 'lib/dry/types.rb', line 253

def self.Types(*namespaces, default: Types::Undefined, **aliases)
  Types::Module.new(Types.container, *namespaces, default: default, **aliases)
end