Class: EnumValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- EnumValidator
- Defined in:
- lib/petstore_api_client/validators/enum_validator.rb
Overview
Custom enum validator - ActiveModel’s inclusion validator doesn’t quite work the way we want for status enums, so rolling our own
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/petstore_api_client/validators/enum_validator.rb', line 6 def validate_each(record, attribute, value) return if value.nil? && [:allow_nil] allowed_values = [:in] || [:within] return if allowed_values.include?(value) record.errors.add( attribute, "must be one of: #{allowed_values.join(", ")}, but got '#{value}'" ) end |