Exception: CSVPlusPlus::Error::ModifierValidationError

Inherits:
ModifierSyntaxError show all
Extended by:
T::Sig
Includes:
PositionalError
Defined in:
lib/csv_plus_plus/error/modifier_validation_error.rb

Overview

An error that can be thrown when a modifier doesn’t pass our validation.

Instance Attribute Summary collapse

Attributes inherited from Error

#wrapped_error

Instance Method Summary collapse

Methods inherited from ModifierSyntaxError

#error_message

Methods inherited from Error

#error_message

Constructor Details

#initialize(modifier, bad_input:, choices: nil, message: nil) ⇒ ModifierValidationError

You must supply either a choices or message

Parameters:

  • modifier (Symbol)

    The modifier being parsed when the bad input was encountered

  • bad_input (String)

    The offending input that caused the error to be thrown

  • choices (Array<Symbol>, nil) (defaults to: nil)

    The choices that value must be one of (but violated)

  • message (String, nil) (defaults to: nil)

    A relevant message to show



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/csv_plus_plus/error/modifier_validation_error.rb', line 30

def initialize(modifier, bad_input:, choices: nil, message: nil)
  message = ::T.let(
    if choices
      "must be one of (#{choices.values.map(&:serialize).join(', ')})"
    else
      ::T.must(message)
    end,
    ::String
  )
  super(message, bad_input:, modifier:)
end

Instance Attribute Details

#bad_inputString (readonly)

The offending input that caused the error to be thrown

Returns:

  • (String)

    the current value of bad_input



12
13
14
# File 'lib/csv_plus_plus/error/modifier_validation_error.rb', line 12

def bad_input
  @bad_input
end

#choicesArray<Symbol>? (readonly)

The choices that value must be one of (but violated)

Returns:

  • (Array<Symbol>, nil)

    the current value of choices



12
13
14
# File 'lib/csv_plus_plus/error/modifier_validation_error.rb', line 12

def choices
  @choices
end

#messageString? (readonly)

A relevant message to show

Returns:

  • (String, nil)

    the current value of message



12
13
14
# File 'lib/csv_plus_plus/error/modifier_validation_error.rb', line 12

def message
  @message
end

#modifierSymbol (readonly)

The modifier being parsed when the bad input was encountered

Returns:

  • (Symbol)

    the current value of modifier



12
13
14
# File 'lib/csv_plus_plus/error/modifier_validation_error.rb', line 12

def modifier
  @modifier
end