class Dry::Types::Constrained
def ===(value)
-
(Boolean)
-
Parameters:
-
value
(Object
) --
def ===(value) valid?(value) end
def call(input)
-
(ConstraintError)
-
Returns:
-
(Object)
-
Parameters:
-
input
(Object
) --
def call(input) try(input) do |result| raise ConstraintError.new(result, input) end.input end
def constrained(options)
- See: Dry::Logic::Operators#and -
Returns:
-
(Constrained)
-
Parameters:
-
options
(Hash
) --
def constrained(options) with(rule: rule & Types.Rule(options)) end
def constrained?
-
(true)
-
def constrained? true end
def decorate?(response)
-
(Boolean)
-
Parameters:
-
response
(Object
) --
def decorate?(response) super || response.kind_of?(Constructor) end
def initialize(type, options)
-
options
(Hash
) -- -
type
(Type
) --
def initialize(type, options) super @rule = options.fetch(:rule) end
def to_ast(meta: true)
- See: Definition#to_ast -
Other tags:
- Api: - public
def to_ast(meta: true) [:constrained, [type.to_ast(meta: meta), rule.to_ast, meta ? self.meta : EMPTY_HASH]] end
def try(input, &block)
-
(Object)
- if block given and try fails -
(Logic::Result, Result)
-
Other tags:
- Yieldreturn: -
Other tags:
- Yieldparam: failure -
Parameters:
-
block
(#call, nil
) -- -
input
(Object
) --
def try(input, &block) result = rule.(input) if result.success? type.try(input, &block) else failure = failure(input, result) block ? yield(failure) : failure end end
def valid?(value)
-
(Boolean)
-
Parameters:
-
value
(Object
) --
def valid?(value) rule.(value).success? && type.valid?(value) end