module Dry::Types::Builder
def constrained(options)
-
(Constrained)
-
Parameters:
-
options
(Hash
) -- constraining rule (see {Types.Rule})
def constrained(options) constrained_type.new(self, rule: Types.Rule(options)) end
def constrained_type
-
(Constrained)
-
def constrained_type Constrained end
def constructor(constructor = nil, **options, &block)
-
(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)
-
(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)
-
(Enum)
-
Parameters:
-
values
(Array
) --
def enum(*values) Enum.new(constrained(included_in: values), values: values) end
def maybe
-
(Maybe)
-
def maybe Maybe.new(Types['strict.nil'] | self) end
def optional
-
(Sum)
-
def optional Types['strict.nil'] | self end
def safe
-
(Safe)
-
def safe Safe.new(self) end
def |(other)
-
(Sum, Sum::Constrained)
-
Parameters:
-
other
(Definition
) --
def |(other) klass = constrained? && other.constrained? ? Sum::Constrained : Sum klass.new(self, other) end