Sha256: 7a72f7db33165793f8f96f6a37b6e297a2320b0953ce3c8ddda24138d56aec05

Contents?: true

Size: 1.14 KB

Versions: 29

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module ActiveModel
  module Validations
    # == \Active \Model Absence Validator
    class AbsenceValidator < EachValidator # :nodoc:
      def validate_each(record, attr_name, value)
        record.errors.add(attr_name, :present, **options) if value.present?
      end
    end

    module HelperMethods
      # Validates that the specified attributes are blank (as defined by
      # Object#present?). Happens by default on save.
      #
      #   class Person < ActiveRecord::Base
      #     validates_absence_of :first_name
      #   end
      #
      # The first_name attribute must be in the object and it must be blank.
      #
      # Configuration options:
      # * <tt>:message</tt> - A custom error message (default is: "must be blank").
      #
      # There is also a list of default options supported by every validator:
      # +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+.
      # See ActiveModel::Validations::ClassMethods#validates for more information.
      def validates_absence_of(*attr_names)
        validates_with AbsenceValidator, _merge_attributes(attr_names)
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 6 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/activemodel-7.0.8.7/lib/active_model/validations/absence.rb
activemodel-7.0.8.7 lib/active_model/validations/absence.rb
activemodel-7.0.8.6 lib/active_model/validations/absence.rb
activemodel-7.0.8.5 lib/active_model/validations/absence.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activemodel-7.0.8.4/lib/active_model/validations/absence.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activemodel-7.0.5.1/lib/active_model/validations/absence.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activemodel-7.0.5.1/lib/active_model/validations/absence.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activemodel-7.0.5.1/lib/active_model/validations/absence.rb
activemodel-7.0.8.4 lib/active_model/validations/absence.rb
activemodel-7.0.8.1 lib/active_model/validations/absence.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activemodel-7.0.3.1/lib/active_model/validations/absence.rb
activemodel-7.0.8 lib/active_model/validations/absence.rb
activemodel-7.0.7.2 lib/active_model/validations/absence.rb
activemodel-7.0.7.1 lib/active_model/validations/absence.rb
activemodel-7.0.7 lib/active_model/validations/absence.rb
activemodel-7.0.6 lib/active_model/validations/absence.rb
activemodel-7.0.5.1 lib/active_model/validations/absence.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activemodel-7.0.3.1/lib/active_model/validations/absence.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/validations/absence.rb
activemodel-7.0.5 lib/active_model/validations/absence.rb