class Dry::Schema::Result
@api public
Monad extension for Result
def self.new(*, **)
- Api: - private
def self.new(*, **) result = super yield(result) if block_given? result.freeze end
def [](name)
- Api: - public
Returns:
-
(Object)
-
Parameters:
-
name
(Symbol
) --
def [](name) output[name] end
def add_error(node)
- Api: - private
def add_error(node) result_ast << node end
def at(at_path, &)
- Api: - private
Returns:
-
(Result)
-
Parameters:
-
path
(Symbol, Array, Path
) --
def at(at_path, &) new(@output, path: Path.new([*path, *Path[at_path]]), &) end
def concat(other)
- Api: - private
def concat(other) result_ast.concat(other.map(&:to_ast)) self end
def deconstruct_keys(_)
- Api: - private
def deconstruct_keys(_) output end
def error?(spec)
- Api: - public
Returns:
-
(Boolean)
-
Parameters:
-
spec
(Symbol, Hash
) --Symbol>
def error?(spec) message_set.any? { |msg| Path[msg.path].include?(Path[spec]) } end
def errors(options = EMPTY_HASH)
- Api: - public
Returns:
-
(MessageSet)
-
Other tags:
- See: #message_set -
def errors(options = EMPTY_HASH) message_set(options) end
def failure?
- Api: - public
Returns:
-
(Boolean)
-
def failure? !success? end
def inspect
- Api: - public
Returns:
-
(String)
-
def inspect "#<#{self.class}#{to_h.inspect} errors=#{errors.to_h.inspect} path=#{path.keys.inspect}>" end
def key?(name)
- Api: - public
Returns:
-
(Boolean)
-
Parameters:
-
name
(Symbol
) --
def key?(name) output.key?(name) end
def message_set(options = EMPTY_HASH)
- Api: - public
Returns:
-
(MessageSet)
-
Options Hash:
(**options)
-
:full
(Boolean
) -- Whether to generate messages that include key names -
:hints
(Boolean
) -- Whether to include hint messages or not -
:locale
(Symbol
) -- Alternative locale (default is :en)
Parameters:
-
options
(Hash
) --
def message_set(options = EMPTY_HASH) message_compiler.with(options).(result_ast) end
def new(output, **opts, &)
- Api: - private
def new(output, **opts, &) self.class.new( output, message_compiler: message_compiler, result_ast: result_ast, **opts, & ) end
def output
- Api: - private
Returns:
-
(Hash)
-
def output path.equal?(Path::EMPTY) ? @output : @output.dig(*path) end
def path
- Api: - private
def path @path || Path::EMPTY end
def replace(value)
- Api: - private
def replace(value) if value.is_a?(output.class) output.replace(value) elsif path.equal?(Path::EMPTY) @output = value else value_holder = path.keys.length > 1 ? @output.dig(*path.to_a[0..-2]) : @output value_holder[path.last] = value end self end
def success?
- Api: - public
Returns:
-
(Boolean)
-
def success? result_ast.empty? end
def to_monad
- Api: - public
Returns:
-
(Dry::Monads::Success, Dry::Monads::Failure)
-
def to_monad if success? Success(self) else Failure(self) end end
def update(hash)
- Api: - private
def update(hash) output.update(hash) self end