summaryrefslogtreecommitdiff
path: root/app/validators/cron_validator.rb
blob: bd48a7a6efbefb365d659a3b670d78abb16019dc (plain)
1
2
3
4
5
6
7
8
9
10
11
# frozen_string_literal: true

# CronValidator
#
# Custom validator for Cron.
class CronValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    cron_parser = Gitlab::Ci::CronParser.new(record.cron, record.cron_timezone)
    record.errors.add(attribute, " is invalid syntax") unless cron_parser.cron_valid?
  end
end