Sha256: 5b52a2ff2f89fbb8485a8df52c85c5a23b8ea45756e3729abae06305e418a420

Contents?: true

Size: 561 Bytes

Versions: 3

Compression:

Stored size: 561 Bytes

Contents

module ActiveModel
  module Validations
    class TruthinessValidator < ActiveModel::EachValidator
      def validate_each(record, attribute, value)
        record.errors.add(attribute, :truthiness, :message => options[:message], :value => value) unless (value.is_a?(FalseClass) || value.is_a?(TrueClass))
      end
    end

    module HelperMethods
      def validates_truthiness_of(*attr_names)
        validates_with TruthinessValidator, _merge_attributes(attr_names)
      end

      alias validates_booleanship_of validates_truthiness_of
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
validates_truthiness-0.1.2 lib/validates_truthiness/validates_truthiness.rb
validates_truthiness-0.1.1 lib/validates_truthiness/validates_truthiness.rb
validates_truthiness-0.1.0 lib/validates_truthiness.rb