Class: Gitlab::Config::Entry::Validators::DurationValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Includes:
LegacyValidationHelpers
Defined in:
lib/gitlab/config/entry/validators.rb

Instance Method Summary collapse

Instance Method Details

#contains_variable?(value) ⇒ Boolean

Returns:



171
172
173
# File 'lib/gitlab/config/entry/validators.rb', line 171

def contains_variable?(value)
  ExpandVariables::VARIABLES_REGEXP.match?(value.to_s)
end

#validate_each(record, attribute, value) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/gitlab/config/entry/validators.rb', line 157

def validate_each(record, attribute, value)
  return if options[:variable] && contains_variable?(value)

  unless validate_duration(value, options[:parser])
    record.errors.add(attribute, 'should be a duration')
  end

  if options[:limit]
    unless validate_duration_limit(value, options[:limit], options[:parser])
      record.errors.add(attribute, 'should not exceed the limit')
    end
  end
end