Sha256: 703f5d418a4efd09f54864884931e19505c1b7dee3f3dd0d1b586f90e4666cb1

Contents?: true

Size: 645 Bytes

Versions: 3

Compression:

Stored size: 645 Bytes

Contents

module ActiveModel
  module Validations
    class NotNullValidator < ActiveModel::EachValidator
      def validate_each(record, attribute, value)
        if value.nil?
          errors_options = options.except(:must_be_set)
          default_message = options[:must_be_set]
          errors_options[:message] ||= default_message if default_message
          record.errors.add(attribute, :must_be_set, **errors_options)
        end
      end
    end

    module HelperMethods
      def validates_not_null_of(*attr_names)
        validates_with ActiveModel::Validations::NotNullValidator, _merge_attributes(attr_names)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
activerecord-databasevalidations-1.0.1 lib/active_model/validations/not_null.rb
activerecord-databasevalidations-1.0.0 lib/active_model/validations/not_null.rb
activerecord-databasevalidations-0.5.1 lib/active_model/validations/not_null.rb