class Eddy::Errors::TypeValidationError

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

Public Class Methods

new(msg = "", element:, arg:) click to toggle source

@param element [Eddy::Models::Element::Base] Element instance that raised the exception. @param arg [Object] Passed argument that caused the exception. @param msg [String] (“”) @return [void]

# 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

Public Instance Methods

wanted_type(el) click to toggle source

@param el [Eddy::Models::Element::Base] Element instance that raised the exception. @return [String]

# 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