Exception: HatiConfig::SettingTypeError

Inherits:
TypeError
  • Object
show all
Defined in:
lib/hati_config/errors.rb

Overview

Custom error raised when a setting type does not match the expected type.

Examples:

Raising an SettingTypeError

raise SettingTypeError.new(:int, "string")
# => raises SettingTypeError with message
# "Expected: <int>. Given: \"string\" which is <String> class."

Instance Method Summary collapse

Constructor Details

#initialize(type, val) ⇒ SettingTypeError

Initializes a new SettingTypeError.

Parameters:

  • type (Symbol) —

    The expected type.

  • val (Object) —

    The value that was provided.



16
17
18
# File 'lib/hati_config/errors.rb', line 16

def initialize(type, val)
  super(type_error_msg(type, val))
end

Instance Method Details

#type_error_msg(type, val) ⇒ String

Generates the error message for the exception.

Parameters:

  • type (Symbol) —

    The expected type.

  • val (Object) —

    The value that was provided.

Returns:

  • (String) —

    The formatted error message.



25
26
27
# File 'lib/hati_config/errors.rb', line 25

def type_error_msg(type, val)
  "Expected: <#{type}>. Given: #{val.inspect} which is <#{val.class}> class."
end