Class: ActiveRecord::Validations::PgEnumValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- ActiveRecord::Validations::PgEnumValidator
- Defined in:
- lib/enum_kit/active_record_patches/validations/pg_enum_validator.rb
Overview
Validates whether an enum’s value is acceptable by comparing with the acceptable values defined in the PostgreSQL database.
Instance Method Summary collapse
-
#validate_each(record, attribute, value) ⇒ Object
Validate the given value is acceptable for the enum.
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
Validate the given value is acceptable for the enum.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/enum_kit/active_record_patches/validations/pg_enum_validator.rb', line 19 def validate_each(record, attribute, value) values = record.class.pg_enum_values(attribute) return if values.include?(value) record.errors.add(attribute, [:message] || :invalid, **.except(:message).merge!( attribute: record.class.human_attribute_name(attribute), values: values.join(', ') )) end |