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
456 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
2019-09-30 07:30:19 -04:00
error! :blank if value.to_s.blank?
2019-09-29 08:43:31 -04:00
error! :codename unless CODENAME_RE.match? value
error! :too_short, count: MIN if value.to_s.length < MIN
error! :too_long, count: MAX if value.to_s.length > MAX
end
end
end