class Dry::Types::Constrained

@api public
Constrained types apply rules to the input

def ===(value)

Other tags:
    Api: - public

Returns:
  • (Boolean) -

Parameters:
  • value (Object) --
def ===(value)
  valid?(value)
end

def call_safe(input, &block)

Other tags:
    Api: - private

Returns:
  • (Object) -
def call_safe(input, &block)
  if rule[input]
    type.call_safe(input, &block)
  else
    yield
  end
end

def call_unsafe(input)

Other tags:
    Api: - private

Returns:
  • (Object) -
def call_unsafe(input)
  result = rule.(input)
  if result.success?
    type.call_unsafe(input)
  else
    raise ConstraintError.new(result, input)
  end
end

def constrained(options)

Other tags:
    Api: - public

Other tags:
    See: Dry::Logic::Operators#and -

Returns:
  • (Constrained) -

Parameters:
  • options (Hash) --
def constrained(options)
  with(rule: rule & Types.Rule(options))
end

def constrained?

Other tags:
    Api: - public

Returns:
  • (true) -
def constrained?
  true
end

def constructor_type

Other tags:
    Api: - private
def constructor_type
  type.constructor_type
end

def decorate?(response)

Other tags:
    Api: - private

Returns:
  • (Boolean) -

Parameters:
  • response (Object) --
def decorate?(response)
  super || response.is_a?(Constructor)
end

def initialize(type, **options)

Other tags:
    Api: - public

Parameters:
  • options (Hash) --
  • type (Type) --
def initialize(type, **options)
  super
  @rule = options.fetch(:rule)
end

def lax

Other tags:
    Api: - public

Returns:
  • (Lax) -
def lax
  type.lax
end

def to_ast(meta: true)

Other tags:
    Api: - public

Other tags:
    See: Nominal#to_ast -
def to_ast(meta: true)
  [:constrained, [type.to_ast(meta: meta), rule.to_ast]]
end

def try(input, &block)

Other tags:
    Api: - public

Returns:
  • (Object) -
  • (Logic::Result) -

Other tags:
    Yieldreturn: -

Other tags:
    Yieldparam: failure -

Parameters:
  • input (Object) --
  • input (Object) --

Overloads:
  • try(input)
  • try(input)
def try(input, &block)
  result = rule.(input)
  if result.success?
    type.try(input, &block)
  else
    failure = failure(input, ConstraintError.new(result, input))
    block_given? ? yield(failure) : failure
  end
end