Sha256: c83078f27acbb33f32dad57351d349b05a5ac3fe23bd23906fc081e844b79484

Contents?: true

Size: 468 Bytes

Versions: 1

Compression:

Stored size: 468 Bytes

Contents

module ActiveModel
  module Validations
    class TruthinessValidator < ActiveModel::EachValidator
      def validate_each(record, attribute, value)
        record.errors[attribute] << "must be either True or False" 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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
validates_truthiness-0.0.1 lib/validates_truthiness.rb