Exception: Eddy::Errors::TypeValidationError

Inherits:
ElementValidationError show all
Defined in:
lib/eddy/errors.rb

Overview

Exception raised when an invalid argument is passed to the value= method of an Models::Element::Base class.

Instance Attribute Summary

Attributes inherited from ElementValidationError

#arg, #element

Element Validation Errors collapse

Methods inherited from ElementValidationError

#element_description

Constructor Details

#initialize(msg = "", element:, arg:) ⇒ void

Parameters:

  • element (Eddy::Models::Element::Base)

    Element instance that raised the exception.

  • arg (Object)

    Passed argument that caused the exception.

  • msg (String) (defaults to: "")

    ("")



73
74
75
76
77
78
79
80
# File 'lib/eddy/errors.rb', line 73

def initialize(msg = "", element:, arg:)
  self.element = element
  self.arg = arg
  if msg.length == 0
    msg << "Value must to be a #{wanted_type(element)}; recieved #{self.arg} (#{self.arg.class.name})"
  end
  super(msg)
end

Instance Method Details

#wanted_type(el) ⇒ String

Parameters:

Returns:

  • (String)


84
85
86
87
88
89
90
91
92
93
# File 'lib/eddy/errors.rb', line 84

def wanted_type(el)
  return case el
         when Eddy::Models::Element::AN then "String"
         when Eddy::Models::Element::B  then "String"
         when Eddy::Models::Element::DT then "Time"
         when Eddy::Models::Element::TM then "Time"
         when Eddy::Models::Element::N  then "Float or Integer"
         when Eddy::Models::Element::R  then "Float or Integer"
         end
end