Exception: CSVPlusPlus::Error::ModifierValidationError

Inherits:
Error
  • Object
show all
Extended by:
T::Sig
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

Instance Method Summary collapse

Constructor Details

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

You must supply either a choices or message

rubocop:disable Metrics/MethodLength

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



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/csv_plus_plus/error/modifier_validation_error.rb', line 42

def initialize(modifier, bad_input:, choices: nil, message: nil)
  @bad_input = bad_input
  @choices = choices
  @modifier = modifier

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

  super(@message)
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

Instance Method Details

#error_message::String

A user-facing error message

Returns:

  • (::String)


64
65
66
# File 'lib/csv_plus_plus/error/modifier_validation_error.rb', line 64

def error_message
  @message
end