Sha256: 8990c89555dcbef8ce8847736a0d1f7ad880ca5d5c9511d605be97146ff5ee1d

Contents?: true

Size: 462 Bytes

Versions: 4

Compression:

Stored size: 462 Bytes

Contents

class BooleanValidator < ActiveModel::EachValidator

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

  private

  FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE'].freeze
  TRUE_VALUES  = [true, 1, '1', 't', 'T', 'true', 'TRUE'].freeze

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
active_validation-2.6.0 lib/active_validation/validators/boolean_validator.rb
active_validation-2.5.0 lib/active_validation/validators/boolean_validator.rb
active_validation-2.4.0 lib/active_validation/validators/boolean_validator.rb
active_validation-2.3.0 lib/active_validation/validators/boolean_validator.rb