Commit 720ed6f6 authored by gfyoung's avatar gfyoung

Enable frozen string in apps/validators/*.rb

Partially addresses #47424.
parent f63e234b
# frozen_string_literal: true
class AbstractPathValidator < ActiveModel::EachValidator class AbstractPathValidator < ActiveModel::EachValidator
extend Gitlab::EncodingHelper extend Gitlab::EncodingHelper
......
# frozen_string_literal: true
class CertificateFingerprintValidator < ActiveModel::EachValidator class CertificateFingerprintValidator < ActiveModel::EachValidator
FINGERPRINT_PATTERN = /\A([a-zA-Z0-9]{2}[\s\-:]?){16,}\z/.freeze FINGERPRINT_PATTERN = /\A([a-zA-Z0-9]{2}[\s\-:]?){16,}\z/.freeze
......
# frozen_string_literal: true
# UrlValidator # UrlValidator
# #
# Custom validator for private keys. # Custom validator for private keys.
......
# frozen_string_literal: true
# UrlValidator # UrlValidator
# #
# Custom validator for private keys. # Custom validator for private keys.
......
# frozen_string_literal: true
# ClusterNameValidator # ClusterNameValidator
# #
# Custom validator for ClusterName. # Custom validator for ClusterName.
......
# frozen_string_literal: true
# ColorValidator # ColorValidator
# #
# Custom validator for web color codes. It requires the leading hash symbol and # Custom validator for web color codes. It requires the leading hash symbol and
......
# frozen_string_literal: true
# CronTimezoneValidator # CronTimezoneValidator
# #
# Custom validator for CronTimezone. # Custom validator for CronTimezone.
......
# frozen_string_literal: true
# CronValidator # CronValidator
# #
# Custom validator for Cron. # Custom validator for Cron.
......
# frozen_string_literal: true
# DurationValidator # DurationValidator
# #
# Validate the format conforms with ChronicDuration # Validate the format conforms with ChronicDuration
......
# frozen_string_literal: true
class EmailValidator < ActiveModel::EachValidator class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value) def validate_each(record, attribute, value)
record.errors.add(attribute, :invalid) unless value =~ Devise.email_regexp record.errors.add(attribute, :invalid) unless value =~ Devise.email_regexp
......
# frozen_string_literal: true
class KeyRestrictionValidator < ActiveModel::EachValidator class KeyRestrictionValidator < ActiveModel::EachValidator
FORBIDDEN = -1 FORBIDDEN = -1
......
# frozen_string_literal: true
# LineCodeValidator # LineCodeValidator
# #
# Custom validator for GitLab line codes. # Custom validator for GitLab line codes.
......
# frozen_string_literal: true
# NamespaceNameValidator # NamespaceNameValidator
# #
# Custom validator for GitLab namespace name strings. # Custom validator for GitLab namespace name strings.
......
# frozen_string_literal: true
class NamespacePathValidator < AbstractPathValidator class NamespacePathValidator < AbstractPathValidator
extend Gitlab::EncodingHelper extend Gitlab::EncodingHelper
......
# frozen_string_literal: true
class ProjectPathValidator < AbstractPathValidator class ProjectPathValidator < AbstractPathValidator
extend Gitlab::EncodingHelper extend Gitlab::EncodingHelper
......
# frozen_string_literal: true
# PublicUrlValidator # PublicUrlValidator
# #
# Custom validator for URLs. This validator works like UrlValidator but # Custom validator for URLs. This validator works like UrlValidator but
......
# frozen_string_literal: true
class TopLevelGroupValidator < ActiveModel::EachValidator class TopLevelGroupValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value) def validate_each(record, attribute, value)
if value&.subgroup? if value&.subgroup?
......
# frozen_string_literal: true
# UrlValidator # UrlValidator
# #
# Custom validator for URLs. # Custom validator for URLs.
......
# frozen_string_literal: true
# VariableDuplicatesValidator # VariableDuplicatesValidator
# #
# This validator is designed for especially the following condition # This validator is designed for especially the following condition
...@@ -22,8 +24,8 @@ class VariableDuplicatesValidator < ActiveModel::EachValidator ...@@ -22,8 +24,8 @@ class VariableDuplicatesValidator < ActiveModel::EachValidator
def validate_duplicates(record, attribute, values) def validate_duplicates(record, attribute, values)
duplicates = values.reject(&:marked_for_destruction?).group_by(&:key).select { |_, v| v.many? }.map(&:first) duplicates = values.reject(&:marked_for_destruction?).group_by(&:key).select { |_, v| v.many? }.map(&:first)
if duplicates.any? if duplicates.any?
error_message = "have duplicate values (#{duplicates.join(", ")})" error_message = +"have duplicate values (#{duplicates.join(", ")})"
error_message += " for #{values.first.send(options[:scope])} scope" if options[:scope] # rubocop:disable GitlabSecurity/PublicSend error_message << " for #{values.first.send(options[:scope])} scope" if options[:scope] # rubocop:disable GitlabSecurity/PublicSend
record.errors.add(attribute, error_message) record.errors.add(attribute, error_message)
end end
end end
......
---
title: Enable frozen string in apps/validators/*.rb
merge_request: 20220
author: gfyoung
type: other
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment