Sha256: e57c3830e9c0b62eb0c3471709f9ad049123b23643668ae26f9edc072c2a5b59

Contents?: true

Size: 434 Bytes

Versions: 10

Compression:

Stored size: 434 Bytes

Contents

class BooleanValidator < ActiveModel::EachValidator
  FALSE_VALUES ||= [false, 0, '0', 'f', 'F', 'false', 'FALSE'].freeze
  TRUE_VALUES  ||= [true, 1, '1', 't', 'T', 'true', 'TRUE'].freeze

  def validate_each(record, attribute, value)
    return if TRUE_VALUES.include?(value) || FALSE_VALUES.include?(value)
    record.errors[attribute] <<
      (options[:message] || I18n.t('active_validation.errors.messages.boolean'))
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
active_validation-4.0.10 lib/active_validation/validators/boolean_validator.rb
active_validation-4.0.9 lib/active_validation/validators/boolean_validator.rb
active_validation-4.0.8 lib/active_validation/validators/boolean_validator.rb
active_validation-4.0.7 lib/active_validation/validators/boolean_validator.rb
active_validation-4.0.6 lib/active_validation/validators/boolean_validator.rb
active_validation-4.0.5 lib/active_validation/validators/boolean_validator.rb
active_validation-4.0.4 lib/active_validation/validators/boolean_validator.rb
active_validation-4.0.3 lib/active_validation/validators/boolean_validator.rb
active_validation-4.0.2 lib/active_validation/validators/boolean_validator.rb
active_validation-4.0.1 lib/active_validation/validators/boolean_validator.rb