Module: Interactor::Validation::Validators::Format

Defined in:
lib/interactor/validation/validators/format.rb

Instance Method Summary collapse

Instance Method Details

#validate_format(param, value, rule) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/interactor/validation/validators/format.rb', line 7

def validate_format(param, value, rule)
  pattern = rule.is_a?(::Hash) ? rule[:with] : rule
  return if value.to_s.match?(pattern)

  msg = rule.is_a?(::Hash) ? rule[:message] : nil
  errors.add(param, :invalid, message: msg || "is invalid")
end