mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
f7de9f17d5
add a new setting for min pm body length use that setting for flags scale entropy check down for pms
20 lines
832 B
Ruby
20 lines
832 B
Ruby
module Validators; end
|
|
class Validators::StrippedLengthValidator < ActiveModel::EachValidator
|
|
def self.validate(record, attribute, value, range)
|
|
unless value.nil?
|
|
stripped_length = value.strip.length
|
|
record.errors.add attribute, (I18n.t('errors.messages.too_short', count: range.begin)) unless
|
|
stripped_length >= range.begin
|
|
record.errors.add attribute, (I18n.t('errors.messages.too_long', count: range.end)) unless
|
|
stripped_length <= range.end
|
|
else
|
|
record.errors.add attribute, (I18n.t('errors.messages.blank'))
|
|
end
|
|
end
|
|
|
|
def validate_each(record, attribute, value)
|
|
# the `in` parameter might be a lambda when the range is dynamic
|
|
range = options[:in].lambda? ? options[:in].call : options[:in]
|
|
self.class.validate(record, attribute, value, range)
|
|
end
|
|
end
|