Exception: CSVPlusPlus::Error::ModifierValidationError
- 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
-
#bad_input ⇒ String
readonly
The offending input that caused the error to be thrown.
-
#choices ⇒ Array<Symbol>?
readonly
The choices that
valuemust be one of (but violated). -
#message ⇒ String?
readonly
A relevant message to show.
-
#modifier ⇒ Symbol
readonly
The modifier being parsed when the bad input was encountered.
Instance Method Summary collapse
-
#error_message ⇒ ::String
Create a relevant error message given @choices or @message (one of them must be supplied).
-
#initialize(modifier, bad_input, choices: nil, message: nil) ⇒ ModifierValidationError
constructor
You must supply either a
choicesormessage.
Constructor Details
#initialize(modifier, bad_input, choices: nil, message: nil) ⇒ ModifierValidationError
You must supply either a choices or message
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/csv_plus_plus/error/modifier_validation_error.rb', line 22 def initialize(modifier, bad_input, choices: nil, message: nil) @bad_input = bad_input @choices = choices @modifier = modifier @message = if @choices "must be one of (#{@choices.map(&:to_s).join(', ')})" else end super(@message) end |
Instance Attribute Details
#bad_input ⇒ String (readonly)
The offending input that caused the error to be thrown
13 14 15 |
# File 'lib/csv_plus_plus/error/modifier_validation_error.rb', line 13 def bad_input @bad_input end |
#choices ⇒ Array<Symbol>? (readonly)
The choices that value must be one of (but violated)
13 14 15 |
# File 'lib/csv_plus_plus/error/modifier_validation_error.rb', line 13 def choices @choices end |
#message ⇒ String? (readonly)
A relevant message to show
13 14 15 |
# File 'lib/csv_plus_plus/error/modifier_validation_error.rb', line 13 def @message end |
#modifier ⇒ Symbol (readonly)
The modifier being parsed when the bad input was encountered
13 14 15 |
# File 'lib/csv_plus_plus/error/modifier_validation_error.rb', line 13 def modifier @modifier end |
Instance Method Details
#error_message ⇒ ::String
Create a relevant error message given @choices or @message (one of them must be supplied).
40 41 42 43 44 45 46 |
# File 'lib/csv_plus_plus/error/modifier_validation_error.rb', line 40 def <<~ERROR_MESSAGE Error parsing modifier: [[#{@modifier}=...]] Bad input: #{@bad_input} Reason: #{@message} ERROR_MESSAGE end |