debian-mirror-gitlab/app/validators/sha_validator.rb

10 lines
247 B
Ruby
Raw Normal View History

2019-03-13 22:55:13 +05:30
# frozen_string_literal: true
class ShaValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if value.blank? || value.match(/\A\h{40}\z/)
record.errors.add(attribute, 'is not a valid SHA')
end
end