Exception: Otoroshi::NotAcceptedError

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

Overview

Manages errors raised when value is not accepted (not included in the “one_of”)

Instance Method Summary collapse

Constructor Details

#initialize(property, accepted_values, array: false) ⇒ NotAcceptedError

Initialize an error

Parameters:

  • property (Symbol)

    name of the property

  • accepted_values (Array)

    accepted values

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

    define if it is an array



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/otoroshi/exceptions.rb', line 43

def initialize(property, accepted_values, array: false)
  # reintegrate the colon for symbols which is lost during interpolation
  to_s = ->(v) { v.is_a?(Symbol) ? ":#{v}" : v }
  accepted_values_list = accepted_values.map { |v| to_s.call(v) }.join(', ')
  msg =
    if array
      ":#{property} contains elements that are not included in [#{accepted_values_list}]"
    else
      ":#{property} is not included in [#{accepted_values_list}]"
    end
  super(msg)
end