Sha256: a359551e843fec76968a4525660907cdb7e8d1ceaf77a98ea1bb8a59270b81b9

Contents?: true

Size: 960 Bytes

Versions: 194

Compression:

Stored size: 960 Bytes

Contents

# frozen_string_literal: true

module ActiveRecord
  module Validations
    class LengthValidator < ActiveModel::Validations::LengthValidator # :nodoc:
      def validate_each(record, attribute, association_or_value)
        if association_or_value.respond_to?(:loaded?) && association_or_value.loaded?
          association_or_value = association_or_value.target.reject(&:marked_for_destruction?)
        end
        super
      end
    end

    module ClassMethods
      # Validates that the specified attributes match the length restrictions supplied.
      # If the attribute is an association, records that are marked for destruction are not counted.
      #
      # See ActiveModel::Validations::HelperMethods.validates_length_of for more information.
      def validates_length_of(*attr_names)
        validates_with LengthValidator, _merge_attributes(attr_names)
      end

      alias_method :validates_size_of, :validates_length_of
    end
  end
end

Version data entries

194 entries across 189 versions & 17 rubygems

Version Path
activerecord-7.1.3.4 lib/active_record/validations/length.rb
activerecord-7.0.8.4 lib/active_record/validations/length.rb
activerecord-6.1.7.8 lib/active_record/validations/length.rb
activerecord-7.2.0.beta1 lib/active_record/validations/length.rb
activerecord-7.1.3.2 lib/active_record/validations/length.rb
activerecord-7.1.3.1 lib/active_record/validations/length.rb
activerecord-7.0.8.1 lib/active_record/validations/length.rb
activerecord-6.1.7.7 lib/active_record/validations/length.rb
activerecord-7.1.3 lib/active_record/validations/length.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activerecord-6.1.6.1/lib/active_record/validations/length.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activerecord-7.0.3.1/lib/active_record/validations/length.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activerecord-7.0.2.3/lib/active_record/validations/length.rb
activerecord-7.1.2 lib/active_record/validations/length.rb
activerecord-7.1.1 lib/active_record/validations/length.rb
activerecord-7.1.0 lib/active_record/validations/length.rb
activerecord-7.1.0.rc2 lib/active_record/validations/length.rb
activerecord-7.1.0.rc1 lib/active_record/validations/length.rb
activerecord-7.1.0.beta1 lib/active_record/validations/length.rb
activerecord-7.0.8 lib/active_record/validations/length.rb
activerecord-7.0.7.2 lib/active_record/validations/length.rb