Sha256: 520616e92e882749dbde5a83e92c29ec5a3c1287912ecf517acc3fad1ca5d0c8

Contents?: true

Size: 585 Bytes

Versions: 89

Compression:

Stored size: 585 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 = 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

89 entries across 89 versions & 1 rubygems

Version Path
spree_core-4.0.9 app/validators/db_maximum_length_validator.rb
spree_core-4.1.15 app/validators/db_maximum_length_validator.rb
spree_core-4.2.7 app/validators/db_maximum_length_validator.rb
spree_core-4.2.6 app/validators/db_maximum_length_validator.rb
spree_core-4.2.5 app/validators/db_maximum_length_validator.rb
spree_core-4.1.14 app/validators/db_maximum_length_validator.rb
spree_core-4.0.8 app/validators/db_maximum_length_validator.rb
spree_core-4.2.4 app/validators/db_maximum_length_validator.rb
spree_core-3.7.14.1 app/validators/db_maximum_length_validator.rb
spree_core-4.2.3.1 app/validators/db_maximum_length_validator.rb
spree_core-4.1.13.1 app/validators/db_maximum_length_validator.rb
spree_core-4.0.7.1 app/validators/db_maximum_length_validator.rb
spree_core-4.2.3 app/validators/db_maximum_length_validator.rb
spree_core-4.2.2 app/validators/db_maximum_length_validator.rb
spree_core-4.2.1 app/validators/db_maximum_length_validator.rb
spree_core-4.0.7 app/validators/db_maximum_length_validator.rb
spree_core-3.7.14 app/validators/db_maximum_length_validator.rb
spree_core-4.2.0 app/validators/db_maximum_length_validator.rb
spree_core-4.2.0.rc5 app/validators/db_maximum_length_validator.rb
spree_core-4.2.0.rc4 app/validators/db_maximum_length_validator.rb