Class: CronValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/cron_validator.rb

Constant Summary collapse

ATTRIBUTE_WHITELIST =
%i[cron freeze_start freeze_end].freeze
NonWhitelistedAttributeError =
Class.new(StandardError)

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object


8
9
10
11
12
13
14
15
# File 'app/validators/cron_validator.rb', line 8

def validate_each(record, attribute, value)
  if ATTRIBUTE_WHITELIST.include?(attribute)
    cron_parser = Gitlab::Ci::CronParser.new(record.public_send(attribute), record.cron_timezone) # rubocop:disable GitlabSecurity/PublicSend
    record.errors.add(attribute, " is invalid syntax") unless cron_parser.cron_valid?
  else
    raise NonWhitelistedAttributeError.new "Non-whitelisted attribute"
  end
end