Class: FullMetalBody::Internal::ReasonableBooleanValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- FullMetalBody::Internal::ReasonableBooleanValidator
- Defined in:
- lib/full_metal_body/internal/reasonable_boolean_validator.rb
Constant Summary collapse
- TRUE_VALUES =
[true, "1", "t", "T", "true", "TRUE", "on", "ON"].to_set.freeze
- FALSE_VALUES =
[false, "0", "f", "F", "false", "FALSE", "off", "OFF"].to_set.freeze
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
8 9 10 11 12 |
# File 'lib/full_metal_body/internal/reasonable_boolean_validator.rb', line 8 def validate_each(record, attribute, value) unless [TRUE_VALUES, FALSE_VALUES].any? { |b| b.include?(value) } record.errors.add(attribute, :not_reasonable_boolean, value: value) end end |