Sha256: 3ebd340c0e686d9ffaff7d3d18447dc27feacc425788cbc02fb6f556937eaa5c

Contents?: true

Size: 666 Bytes

Versions: 9

Compression:

Stored size: 666 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)
    Spree::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 = record.class.columns_hash[attribute.to_s].limit
    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

9 entries across 9 versions & 1 rubygems

Version Path
spree_core-4.10.1 app/validators/db_maximum_length_validator.rb
spree_core-4.10.0 app/validators/db_maximum_length_validator.rb
spree_core-4.9.0 app/validators/db_maximum_length_validator.rb
spree_core-4.8.3 app/validators/db_maximum_length_validator.rb
spree_core-4.8.2 app/validators/db_maximum_length_validator.rb
spree_core-4.7.3 app/validators/db_maximum_length_validator.rb
spree_core-4.7.2 app/validators/db_maximum_length_validator.rb
spree_core-4.7.1 app/validators/db_maximum_length_validator.rb
spree_core-4.7.0 app/validators/db_maximum_length_validator.rb