Set chars via env
This commit is contained in:
parent
db3dc2ab83
commit
bb7024bf3f
1 changed files with 7 additions and 4 deletions
|
@ -1,20 +1,23 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class StatusLengthValidator < ActiveModel::Validator
|
||||
MAX_CHARS = 500
|
||||
URL_PLACEHOLDER_CHARS = 23
|
||||
URL_PLACEHOLDER = 'x' * 23
|
||||
|
||||
def max_chars
|
||||
@max_chars ||= ENV.fetch('MAX_CHARACTERS', 500).to_i
|
||||
end
|
||||
|
||||
def validate(status)
|
||||
return unless status.local? && !status.reblog?
|
||||
|
||||
status.errors.add(:text, I18n.t('statuses.over_character_limit', max: MAX_CHARS)) if too_long?(status)
|
||||
status.errors.add(:text, I18n.t('statuses.over_character_limit', max: max_chars)) if too_long?(status)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def too_long?(status)
|
||||
countable_length(combined_text(status)) > MAX_CHARS
|
||||
countable_length(combined_text(status)) > max_chars
|
||||
end
|
||||
|
||||
def countable_length(str)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue