1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/app/validators/codename_validator.rb

18 lines
453 B
Ruby
Raw Normal View History

2019-09-29 08:43:31 -04:00
# frozen_string_literal: true
class CodenameValidator < ApplicationEachValidator
class Validation < Validation
CODENAME_RE = /\A[a-z][a-z0-9]*(_[a-z0-9]+)*\z/.freeze
MIN = 3
MAX = 36
def perform
error! :blank if str_value.blank?
2019-09-29 08:43:31 -04:00
error! :codename unless CODENAME_RE.match? value
error! :too_short, count: MIN if str_value.length < MIN
error! :too_long, count: MAX if str_value.length > MAX
2019-09-29 08:43:31 -04:00
end
end
end