Sha256: f9e98546c901dda784d0bb06d18fffa030019a0dd78e70b7c43962dc5a2cb5a0

Contents?: true

Size: 824 Bytes

Versions: 24

Compression:

Stored size: 824 Bytes

Contents

##
# Validates a field based on the maximum length of the underlying DB field, if there is one.
class DbMaximumLengthValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
      `DbMaximumLengthValidator` is deprecated and will be removed in Spree 5.0.
      Please remove any `db_maximum_length: true` validations from your codebase
    DEPRECATION

    limit = if defined?(Globalize)
              record.class.translation_class.columns_hash[attribute.to_s].limit
            else
              record.class.columns_hash[attribute.to_s].limit
            end
    value = record[attribute.to_sym]
    if value && limit && value.to_s.length > limit
      record.errors.add(attribute.to_sym, :too_long, count: limit)
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
spree_core-4.6.6 app/validators/db_maximum_length_validator.rb
spree_core-4.5.5 app/validators/db_maximum_length_validator.rb
spree_core-4.3.3 app/validators/db_maximum_length_validator.rb
spree_core-4.4.1 app/validators/db_maximum_length_validator.rb
spree_core-4.5.4 app/validators/db_maximum_length_validator.rb
spree_core-4.6.5 app/validators/db_maximum_length_validator.rb
spree_core-4.6.4 app/validators/db_maximum_length_validator.rb
spree_core-4.6.3 app/validators/db_maximum_length_validator.rb
spree_core-4.6.2 app/validators/db_maximum_length_validator.rb
spree_core-4.6.1 app/validators/db_maximum_length_validator.rb
spree_core-4.6.0 app/validators/db_maximum_length_validator.rb
spree_core-4.5.3 app/validators/db_maximum_length_validator.rb
spree_core-4.5.2 app/validators/db_maximum_length_validator.rb
spree_core-4.5.1 app/validators/db_maximum_length_validator.rb
spree_core-4.5.0 app/validators/db_maximum_length_validator.rb
spree_core-4.3.2 app/validators/db_maximum_length_validator.rb
spree_core-4.4.0 app/validators/db_maximum_length_validator.rb
spree_core-4.4.0.rc2 app/validators/db_maximum_length_validator.rb
spree_core-4.3.1 app/validators/db_maximum_length_validator.rb
spree_core-4.4.0.rc1 app/validators/db_maximum_length_validator.rb