extracted boolean validation logic into stand-alone validator
This commit is contained in:
12
lib/active_model/validations/boolean_presence_validator.rb
Normal file
12
lib/active_model/validations/boolean_presence_validator.rb
Normal file
@ -0,0 +1,12 @@
|
||||
module ActiveModel
|
||||
module Validations
|
||||
class BooleanPresenceValidator < EachValidator
|
||||
def validate(record)
|
||||
[attributes].flatten.each do |attribute|
|
||||
value = record.send(:read_attribute_for_validation, attribute)
|
||||
record.errors.add(attribute, nil, options) unless [false, true].include?(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user