class Dry::Types::Constrained::Coercible
@api public
Common coercion-related API for constrained types
def call_safe(input)
- Api: - private
Returns:
-
(Object)
-
def call_safe(input) coerced = type.call_safe(input) { return yield } if rule[coerced] coerced else yield(coerced) end end
def call_unsafe(input)
- Api: - private
Returns:
-
(Object)
-
def call_unsafe(input) coerced = type.call_unsafe(input) result = rule.(coerced) if result.success? coerced else raise ConstraintError.new(result, input) end end
def try(input, &)
- Api: - public
Other tags:
- See: Dry::Types::Constrained#try -
def try(input, &) result = type.try(input) if result.success? validation = rule.(result.input) if validation.success? result else failure = failure(result.input, ConstraintError.new(validation, input)) block_given? ? yield(failure) : failure end else block_given? ? yield(result) : result end end