class Dry::Types::Constrained
@api public
Constrained types apply rules to the input
def ===(value)
- Api: - public
Returns:
-
(Boolean)
-
Parameters:
-
value
(Object
) --
def ===(value) valid?(value) end
def call_safe(input, &block)
- 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)
- 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)
- 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?
- Api: - public
Returns:
-
(true)
-
def constrained? true end
def constructor_type
- Api: - private
def constructor_type type.constructor_type end
def decorate?(response)
- Api: - private
Returns:
-
(Boolean)
-
Parameters:
-
response
(Object
) --
def decorate?(response) super || response.is_a?(Constructor) end
def initialize(type, **options)
- Api: - public
Parameters:
-
options
(Hash
) -- -
type
(Type
) --
def initialize(type, **options) super @rule = options.fetch(:rule) end
def lax
- Api: - public
Returns:
-
(Lax)
-
def lax type.lax end
def to_ast(meta: true)
- 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)
- 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