class Dry::Schema::Result

@api public
Monad extension for Result

def self.new(*, **)

Other tags:
    Api: - private
def self.new(*, **)
  result = super
  yield(result) if block_given?
  result.freeze
end

def [](name)

Other tags:
    Api: - public

Returns:
  • (Object) -

Parameters:
  • name (Symbol) --
def [](name)
  output[name]
end

def add_error(node)

Other tags:
    Api: - private
def add_error(node)
  result_ast << node
end

def at(at_path, &)

Other tags:
    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)

Other tags:
    Api: - private
def concat(other)
  result_ast.concat(other.map(&:to_ast))
  self
end

def deconstruct_keys(_)

Other tags:
    Api: - private
def deconstruct_keys(_)
  output
end

def error?(spec)

Other tags:
    Api: - public

Returns:
  • (Boolean) -

Parameters:
  • spec (Symbol, HashSymbol>) --
def error?(spec)
  message_set.any? { |msg| Path[msg.path].include?(Path[spec]) }
end

def errors(options = EMPTY_HASH)

Other tags:
    Api: - public

Returns:
  • (MessageSet) -

Other tags:
    See: #message_set -
def errors(options = EMPTY_HASH)
  message_set(options)
end

def failure?

Other tags:
    Api: - public

Returns:
  • (Boolean) -
def failure?
  !success?
end

def inspect

Other tags:
    Api: - public

Returns:
  • (String) -
def inspect
  "#<#{self.class}#{to_h.inspect} errors=#{errors.to_h.inspect} path=#{path.keys.inspect}>"
end

def key?(name)

Other tags:
    Api: - public

Returns:
  • (Boolean) -

Parameters:
  • name (Symbol) --
def key?(name)
  output.key?(name)
end

def message_set(options = EMPTY_HASH)

Other tags:
    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, &)

Other tags:
    Api: - private
def new(output, **opts, &)
  self.class.new(
    output,
    message_compiler: message_compiler,
    result_ast: result_ast,
    **opts,
    &
  )
end

def output

Other tags:
    Api: - private

Returns:
  • (Hash) -
def output
  path.equal?(Path::EMPTY) ? @output : @output.dig(*path)
end

def path

Other tags:
    Api: - private
def path
  @path || Path::EMPTY
end

def replace(value)

Other tags:
    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?

Other tags:
    Api: - public

Returns:
  • (Boolean) -
def success?
  result_ast.empty?
end

def to_monad

Other tags:
    Api: - public

Returns:
  • (Dry::Monads::Success, Dry::Monads::Failure) -
def to_monad
  if success?
    Success(self)
  else
    Failure(self)
  end
end

def update(hash)

Other tags:
    Api: - private
def update(hash)
  output.update(hash)
  self
end