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-3.5.0.rc1 app/validators/db_maximum_length_validator.rb
spree_core-3.4.5 app/validators/db_maximum_length_validator.rb
spree_core-3.4.4 app/validators/db_maximum_length_validator.rb
spree_core-3.4.3 app/validators/db_maximum_length_validator.rb
spree_core-3.4.2 app/validators/db_maximum_length_validator.rb
spree_core-3.4.1 app/validators/db_maximum_length_validator.rb
spree_core-3.4.0 app/validators/db_maximum_length_validator.rb
spree_core-3.4.0.rc2 app/validators/db_maximum_length_validator.rb
spree_core-3.4.0.rc1 app/validators/db_maximum_length_validator.rb