Class: EnumAttributeValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/trax/validators/enum_attribute_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(object, attribute, value) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/trax/validators/enum_attribute_validator.rb', line 2

def validate_each(object, attribute, value)
  enum_attribute = object.class.fields_module[attribute]

  unless value.is_a?(enum_attribute) && enum_attribute === value
    object.errors[attribute] = "#{value} is not an allowed value"
  end
end