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

17 lines
453 B
Ruby

# 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?
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
end
end
end