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
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.8.7/lib/active_record/validations/length.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/validations/length.rb
activerecord-8.0.1 lib/active_record/validations/length.rb
activerecord-8.0.0.1 lib/active_record/validations/length.rb
activerecord-7.2.2.1 lib/active_record/validations/length.rb
activerecord-7.1.5.1 lib/active_record/validations/length.rb
activerecord-7.0.8.7 lib/active_record/validations/length.rb
activerecord-8.0.0 lib/active_record/validations/length.rb
activerecord-7.2.2 lib/active_record/validations/length.rb
activerecord-7.1.5 lib/active_record/validations/length.rb
activerecord-8.0.0.rc2 lib/active_record/validations/length.rb
activerecord-7.2.1.2 lib/active_record/validations/length.rb
activerecord-7.1.4.2 lib/active_record/validations/length.rb
activerecord-7.0.8.6 lib/active_record/validations/length.rb
activerecord-6.1.7.10 lib/active_record/validations/length.rb
activerecord-8.0.0.rc1 lib/active_record/validations/length.rb
activerecord-6.1.7.9 lib/active_record/validations/length.rb
activerecord-7.2.1.1 lib/active_record/validations/length.rb
activerecord-7.1.4.1 lib/active_record/validations/length.rb
activerecord-7.0.8.5 lib/active_record/validations/length.rb