Welcome to mirror list, hosted at ThFree Co, Russian Federation.

duration_validator.rb « validators « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 10ff44031c6616101a1e0ae7ad85e368ef606360 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# DurationValidator
#
# Validate the format conforms with ChronicDuration
#
# Example:
#
#   class ApplicationSetting < ActiveRecord::Base
#     validates :default_artifacts_expire_in, presence: true, duration: true
#   end
#
class DurationValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    ChronicDuration.parse(value)
  rescue ChronicDuration::DurationParseError
    record.errors.add(attribute, "is not a correct duration")
  end
end