class NoBrainer::Error::InvalidType

Attributes

attr_name[RW]
error[RW]
model[RW]
type[RW]
value[RW]

Public Class Methods

new(options={}) click to toggle source
# File lib/no_brainer/error.rb, line 33
def initialize(options={})
  update(options)
end

Public Instance Methods

human_type_name() click to toggle source
# File lib/no_brainer/error.rb, line 42
def human_type_name
  type.to_s.underscore.humanize.downcase
end
message() click to toggle source
Calls superclass method
# File lib/no_brainer/error.rb, line 51
def message
  return super unless model && attr_name && error
  value = self.value
  mock = model.allocate
  mock.singleton_class.send(:define_method, :read_attribute_for_validation) { |_| value }
  mock.errors.add(attr_name, :invalid_type, **error)
  mock.errors.full_messages.first
end
update(options={}) click to toggle source
# File lib/no_brainer/error.rb, line 37
def update(options={})
  options.assert_valid_keys(:model, :attr_name, :type, :value, :error)
  options.each { |k,v| instance_variable_set("@#{k}", v) }
end