Sha256: 685076e53b9da257ab52fc7f754860d5ece3f053602ed6dab0d836191b325841
Contents?: true
Size: 660 Bytes
Versions: 1
Compression:
Stored size: 660 Bytes
Contents
module Riveter class BooleanessValidator < ActiveModel::EachValidator def initialize(options) @allow_nil, @allow_blank = options.delete(:allow_nil), options.delete(:allow_blank) super end def validate_each(record, attribute, value) return if (@allow_nil && value.nil?) || (@allow_blank && value.blank?) unless [true, false].include?(value) record.errors.add(attribute, :booleaness, :value => value) end end end end # add compatibility with ActiveModel validates method which # matches option keys to their validator class ActiveModel::Validations::BooleanessValidator = Riveter::BooleanessValidator
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
riveter-0.0.1 | lib/riveter/booleaness_validator.rb |