module Dry::Types::Builder

def constrained(options)

Other tags:
    Api: - public

Returns:
  • (Constrained) -

Parameters:
  • options (Hash) -- constraining rule (see {Types.Rule})
def constrained(options)
  constrained_type.new(self, rule: Types.Rule(options))
end

def constrained_type

Other tags:
    Api: - private

Returns:
  • (Class) -
def constrained_type
  Constrained
end

def constructor(constructor = nil, **options, &block)

Other tags:
    Api: - public

Returns:
  • (Constructor) -

Parameters:
  • block (#call, nil) --
  • options (Hash) --
  • constructor (#call, nil) --
def constructor(constructor = nil, **options, &block)
  constructor_type.new(with(**options), fn: constructor || block)
end

def constructor_type

Other tags:
    Api: - private

Returns:
  • (Class) -
def constructor_type
  Constructor
end

def default(input = Undefined, options = EMPTY_HASH, &block)

Other tags:
    Api: - public

Returns:
  • (Default) -

Raises:
  • (ConstraintError) -

Parameters:
  • block (#call, nil) --
  • options (Hash) --
  • input (Object) --
def default(input = Undefined, options = EMPTY_HASH, &block)
  unless input.frozen? || options[:shared]
    where = Dry::Core::Deprecations::STACK.()
    Dry::Core::Deprecations.warn(
      "#{input.inspect} is mutable."\
      ' Be careful: types will return the same instance of the default'\
      ' value every time. Call `.freeze` when setting the default'\
      ' or pass `shared: true` to discard this warning.'\
      "\n#{where}",
      tag: :'dry-types'
    )
  end
  value = input.equal?(Undefined) ? block : input
  if value.respond_to?(:call) || valid?(value)
    Default[value].new(self, value)
  else
    raise ConstraintError.new("default value #{value.inspect} violates constraints", value)
  end
end

def enum(*values)

Other tags:
    Api: - public

Returns:
  • (Enum) -

Parameters:
  • values (Array) --
def enum(*values)
  mapping =
    if values.length == 1 && values[0].is_a?(::Hash)
      values[0]
    else
      ::Hash[values.zip(values)]
    end
  Enum.new(constrained(included_in: mapping.keys), mapping: mapping)
end

def lax

Other tags:
    Api: - public

Returns:
  • (Lax) -
def lax
  Lax.new(self)
end

def maybe

Other tags:
    Api: - public

Returns:
  • (Maybe) -
def maybe
  Maybe.new(Types['strict.nil'] | self)
end

def optional

Other tags:
    Api: - public

Returns:
  • (Sum) -
def optional
  Types['strict.nil'] | self
end

def |(other)

Other tags:
    Api: - private

Returns:
  • (Sum, Sum::Constrained) -

Parameters:
  • other (Type) --
def |(other)
  klass = constrained? && other.constrained? ? Sum::Constrained : Sum
  klass.new(self, other)
end