Sha256: 56c8f6b48f0fe9e0f32c8a94b2169f611f6616dd93fc55a886731ab9f069b8d6
Contents?: true
Size: 788 Bytes
Versions: 47
Compression:
Stored size: 788 Bytes
Contents
module Spree module Validations ## # Validates a field based on the maximum length of the underlying DB field, if there is one. class DbMaximumLengthValidator < ActiveModel::Validator def initialize(options) super @field = options[:field].to_s raise ArgumentError.new("a field must be specified to the validator") if @field.blank? end def validate(record) warn "`Spree::Validations::DbMaximumLengthValidator` is deprecated. Use `DbMaximumLengthValidator` instead." limit = record.class.columns_hash[@field].limit value = record[@field.to_sym] if value && limit && value.to_s.length > limit record.errors.add(@field.to_sym, :too_long, count: limit) end end end end end
Version data entries
47 entries across 47 versions & 2 rubygems