Sha256: 3d674716b9cc4f2eacb1dd8fb047031c54c17deda2bd72afd784afdfcdfbbe1a

Contents?: true

Size: 435 Bytes

Versions: 30

Compression:

Stored size: 435 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)
    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

30 entries across 30 versions & 1 rubygems

Version Path
spree_core-3.1.14 app/validators/db_maximum_length_validator.rb
spree_core-3.1.13 app/validators/db_maximum_length_validator.rb
spree_core-3.2.7 app/validators/db_maximum_length_validator.rb
spree_core-3.1.12 app/validators/db_maximum_length_validator.rb
spree_core-3.2.6 app/validators/db_maximum_length_validator.rb
spree_core-3.1.11 app/validators/db_maximum_length_validator.rb
spree_core-3.1.10 app/validators/db_maximum_length_validator.rb
spree_core-3.2.5 app/validators/db_maximum_length_validator.rb
spree_core-3.1.9 app/validators/db_maximum_length_validator.rb
spree_core-3.2.4 app/validators/db_maximum_length_validator.rb
spree_core-3.1.8 app/validators/db_maximum_length_validator.rb
spree_core-3.1.7 app/validators/db_maximum_length_validator.rb
spree_core-3.2.3 app/validators/db_maximum_length_validator.rb
spree_core-3.2.2 app/validators/db_maximum_length_validator.rb
spree_core-3.1.6 app/validators/db_maximum_length_validator.rb
spree_core-3.1.5 app/validators/db_maximum_length_validator.rb
spree_core-3.2.1 app/validators/db_maximum_length_validator.rb
spree_core-3.2.0 app/validators/db_maximum_length_validator.rb
spree_core-3.1.4 app/validators/db_maximum_length_validator.rb
spree_core-3.2.0.rc3 app/validators/db_maximum_length_validator.rb