Module: Dry::Validation::Hints::ResultExtensions

Defined in:
lib/dry/validation/extensions/hints.rb

Overview

Hints extensions for Result

Instance Method Summary collapse

Instance Method Details

#errors(new_options = EMPTY_HASH) ⇒ MessageSet

Return error messages excluding hints

Parameters:

  • new_options (Hash) (defaults to: EMPTY_HASH)

Options Hash (new_options):

  • :locale (Symbol)

    Set locale for messages

  • :hints (Boolean)

    Enable/disable hints

  • :full (Boolean)

    Get messages that include key names

Returns:


36
37
38
39
# File 'lib/dry/validation/extensions/hints.rb', line 36

def errors(new_options = EMPTY_HASH)
  opts = new_options.merge(hints: false)
  @errors.with(schema_errors(opts), opts)
end

#hints(new_options = EMPTY_HASH) ⇒ MessageSet

Return hint messages

Parameters:

  • new_options (Hash) (defaults to: EMPTY_HASH)

Options Hash (new_options):

  • :locale (Symbol)

    Set locale for messages

  • :hints (Boolean)

    Enable/disable hints

  • :full (Boolean)

    Get messages that include key names

Returns:


59
60
61
# File 'lib/dry/validation/extensions/hints.rb', line 59

def hints(new_options = EMPTY_HASH)
  schema_result.hints(new_options)
end

#messages(new_options = EMPTY_HASH) ⇒ MessageSet

Return errors and hints

Parameters:

  • new_options (Hash) (defaults to: EMPTY_HASH)

Options Hash (new_options):

  • :locale (Symbol)

    Set locale for messages

  • :hints (Boolean)

    Enable/disable hints

  • :full (Boolean)

    Get messages that include key names

Returns:


48
49
50
# File 'lib/dry/validation/extensions/hints.rb', line 48

def messages(new_options = EMPTY_HASH)
  errors.with(hints.to_a, options.merge(**new_options))
end