Sha256: 1811defe13e6b82e4232bfaa225553b87f374df7b219401dd38d08a951362f69

Contents?: true

Size: 431 Bytes

Versions: 1

Compression:

Stored size: 431 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, I18n.t("active_validation.errors.messages.boolean"))
    end
  end

  private

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

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_validation-3.0.0 lib/active_validation/validators/boolean_validator.rb