Exception: Otoroshi::WrongTypeError

Inherits:
Error
  • Object
show all
Defined in:
lib/otoroshi/exceptions.rb

Overview

Manages errors raised when value type is not as expected

Instance Method Summary collapse

Constructor Details

#initialize(property, type, array: false) ⇒ WrongTypeError

Initialize an error

Parameters:

  • property (Symbol)

    name of the property

  • type (Class)

    class to match

  • array (true, false) (defaults to: false)

    define if it is an array



13
14
15
16
17
18
19
20
21
22
# File 'lib/otoroshi/exceptions.rb', line 13

def initialize(property, type, array: false)
  expected_type = type.is_a?(Array) ? type.first || Object : type
  msg =
    if array
      ":#{property} contains elements that are not instances of #{expected_type}"
    else
      ":#{property} is not an instance of #{expected_type}"
    end
  super(msg)
end