module Dry::Types::Builder

def constrained(options)

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

Returns:
  • (Constrained) -
def constrained_type
  Constrained
end

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

Returns:
  • (Constructor) -

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

def default(input = Undefined, &block)

Returns:
  • (Default) -

Raises:
  • (ConstraintError) -

Parameters:
  • block (#call) --
  • input (Object) --
def default(input = Undefined, &block)
  value = input == Undefined ? block : input
  if value.is_a?(Proc) || valid?(value)
    Default[value].new(self, value)
  else
    raise ConstraintError.new("default value #{value.inspect} violates constraints", value)
  end
end

def enum(*values)

Returns:
  • (Enum) -

Parameters:
  • values (Array) --
def enum(*values)
  Enum.new(constrained(included_in: values), values: values)
end

def maybe

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

def optional

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

def safe

Returns:
  • (Safe) -
def safe
  Safe.new(self)
end

def |(other)

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

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