Exception: Otoroshi::OneOfError

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

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(property, values) ⇒ OneOfError

Returns a new instance of OneOfError.

Examples:

":fruit is not in [:apple, :pear]"

Parameters:

  • property (Symbol)

    name of the property

  • values (Array)

    accepted values



25
26
27
28
29
30
# File 'lib/otoroshi/exceptions.rb', line 25

def initialize(property, values)
  # reintegrate the colon for symbols which is lost during interpolation
  to_s = ->(v) { v.is_a?(Symbol) ? ":#{v}" : v }
  list = values.map { |v| to_s.call(v) }.join(', ')
  super ":#{property} is not in [#{list}]"
end