Module: CMDx::Validators::Format
Overview
Validates that a value matches a ‘:with` regex and/or does not match a `:without` regex. Both may be combined; at least one is required.
Instance Method Summary collapse
Instance Method Details
#call(value, options = EMPTY_HASH) ⇒ Validators::Failure?
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/cmdx/validators/format.rb', line 18 def call(value, = EMPTY_HASH) match = case in with:, without: value&.match?(with) && !value&.match?(without) in with: value&.match?(with) in without: !value&.match?(without) else raise ArgumentError, "format validator requires :with and/or :without option" end return if match Failure.new([:message] || I18nProxy.t("cmdx.validators.format")) end |