DEV: Remove logical OR assignment of constants (#29201)

Constants should always be only assigned once. The logical OR assignment
of a constant is a relic of the past before we used zeitwerk for
autoloading and had bugs where a file could be loaded twice resulting in
constant redefinition warnings.
This commit is contained in:
Alan Guo Xiang Tan
2024-10-16 10:09:07 +08:00
committed by GitHub
parent f3f37c9019
commit 322a3be2db
112 changed files with 267 additions and 267 deletions

View File

@@ -6,7 +6,7 @@ class AdminDashboardData
cattr_reader :problem_messages, default: []
# kept for backward compatibility
GLOBAL_REPORTS ||= []
GLOBAL_REPORTS = []
PROBLEM_MESSAGE_PREFIX = "admin-problem:"
SCHEDULED_PROBLEM_STORAGE_KEY = "admin-found-scheduled-problems-list"

View File

@@ -1,8 +1,8 @@
# frozen_string_literal: true
class BackupLocationSiteSetting < EnumSiteSetting
LOCAL ||= "local"
S3 ||= "s3"
LOCAL = "local"
S3 = "s3"
def self.valid_value?(val)
values.any? { |v| v[:value] == val }

View File

@@ -4,7 +4,7 @@ module HasCustomFields
extend ActiveSupport::Concern
module Helpers
CUSTOM_FIELD_TRUE ||= %w[1 t true T True TRUE].freeze
CUSTOM_FIELD_TRUE = %w[1 t true T True TRUE].freeze
end
class FieldDescriptor < Struct.new(:type, :max_length)

View File

@@ -1,9 +1,9 @@
# frozen_string_literal: true
class Draft < ActiveRecord::Base
NEW_TOPIC ||= "new_topic"
NEW_PRIVATE_MESSAGE ||= "new_private_message"
EXISTING_TOPIC ||= "topic_"
NEW_TOPIC = "new_topic"
NEW_PRIVATE_MESSAGE = "new_private_message"
EXISTING_TOPIC = "topic_"
belongs_to :user

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
class EmailLog < ActiveRecord::Base
CRITICAL_EMAIL_TYPES ||=
CRITICAL_EMAIL_TYPES =
Set.new %w[
account_created
admin_login

View File

@@ -4,9 +4,9 @@ class Emoji
# update this to clear the cache
EMOJI_VERSION = "12"
FITZPATRICK_SCALE ||= %w[1f3fb 1f3fc 1f3fd 1f3fe 1f3ff]
FITZPATRICK_SCALE = %w[1f3fb 1f3fc 1f3fd 1f3fe 1f3ff]
DEFAULT_GROUP ||= "default"
DEFAULT_GROUP = "default"
include ActiveModel::SerializerSupport

View File

@@ -5,12 +5,12 @@ class GlobalSetting
define_singleton_method(key) { provider.lookup(key, default) }
end
VALID_SECRET_KEY ||= /\A[0-9a-f]{128}\z/
VALID_SECRET_KEY = /\A[0-9a-f]{128}\z/
# this is named SECRET_TOKEN as opposed to SECRET_KEY_BASE
# for legacy reasons
REDIS_SECRET_KEY ||= "SECRET_TOKEN"
REDIS_SECRET_KEY = "SECRET_TOKEN"
REDIS_VALIDATE_SECONDS ||= 30
REDIS_VALIDATE_SECONDS = 30
# In Rails secret_key_base is used to encrypt the cookie store
# the cookie store contains session data

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
class ImapSyncLog < ActiveRecord::Base
RETAIN_LOGS_DAYS ||= 5
RETAIN_LOGS_DAYS = 5
belongs_to :group

View File

@@ -53,7 +53,7 @@ class LocaleSiteSetting < EnumSiteSetting
@lock.synchronize { @values = @language_names = @supported_locales = nil }
end
FALLBACKS ||= { en_GB: :en }
FALLBACKS = { en_GB: :en }
def self.fallback_locale(locale)
fallback_locale = FALLBACKS[locale.to_sym]

View File

@@ -6,7 +6,7 @@ class OptimizedImage < ActiveRecord::Base
# BUMP UP if optimized image algorithm changes
VERSION = 2
URL_REGEX ||= %r{(/optimized/\dX[/\.\w]*/([a-zA-Z0-9]+)[\.\w]*)}
URL_REGEX = %r{(/optimized/\dX[/\.\w]*/([a-zA-Z0-9]+)[\.\w]*)}
def self.lock(upload_id, width, height)
@hostname ||= Discourse.os_hostname
@@ -185,7 +185,7 @@ class OptimizedImage < ActiveRecord::Base
paths.each { |path| raise Discourse::InvalidAccess unless safe_path?(path) }
end
IM_DECODERS ||= /\A(jpe?g|png|ico|gif|webp|avif)\z/i
IM_DECODERS = /\A(jpe?g|png|ico|gif|webp|avif)\z/i
def self.prepend_decoder!(path, ext_path = nil, opts = nil)
opts ||= {}

View File

@@ -77,11 +77,11 @@ class Post < ActiveRecord::Base
:skip_unique_check,
:skip_validation
MISSING_UPLOADS ||= "missing uploads"
MISSING_UPLOADS_IGNORED ||= "missing uploads ignored"
NOTICE ||= "notice"
MISSING_UPLOADS = "missing uploads"
MISSING_UPLOADS_IGNORED = "missing uploads ignored"
NOTICE = "notice"
SHORT_POST_CHARS ||= 1200
SHORT_POST_CHARS = 1200
register_custom_field_type(MISSING_UPLOADS, :json)
register_custom_field_type(MISSING_UPLOADS_IGNORED, :boolean)

View File

@@ -1,9 +1,9 @@
# frozen_string_literal: true
class RemoveMutedTagsFromLatestSiteSetting < EnumSiteSetting
ALWAYS ||= "always"
ONLY_MUTED ||= "only_muted"
NEVER ||= "never"
ALWAYS = "always"
ONLY_MUTED = "only_muted"
NEVER = "never"
def self.valid_value?(val)
values.any? { |v| v[:value] == val }

View File

@@ -697,7 +697,7 @@ class Topic < ActiveRecord::Base
!self.closed?
end
MAX_SIMILAR_BODY_LENGTH ||= 200
MAX_SIMILAR_BODY_LENGTH = 200
def self.similar_to(title, raw, user = nil)
return [] if SiteSetting.max_similar_results == 0
@@ -1728,7 +1728,7 @@ class Topic < ActiveRecord::Base
DB.exec(sql, user_id: user.id, topic_id: id) > 0
end
TIME_TO_FIRST_RESPONSE_SQL ||= <<-SQL
TIME_TO_FIRST_RESPONSE_SQL = <<-SQL
SELECT AVG(t.hours)::float AS "hours", t.created_at AS "date"
FROM (
SELECT t.id, t.created_at::date AS created_at, EXTRACT(EPOCH FROM MIN(p.created_at) - t.created_at)::float / 3600.0 AS "hours"
@@ -1741,7 +1741,7 @@ class Topic < ActiveRecord::Base
ORDER BY t.created_at
SQL
TIME_TO_FIRST_RESPONSE_TOTAL_SQL ||= <<-SQL
TIME_TO_FIRST_RESPONSE_TOTAL_SQL = <<-SQL
SELECT AVG(t.hours)::float AS "hours"
FROM (
SELECT t.id, EXTRACT(EPOCH FROM MIN(p.created_at) - t.created_at)::float / 3600.0 AS "hours"
@@ -1787,7 +1787,7 @@ class Topic < ActiveRecord::Base
total.first["hours"].to_f.round(2)
end
WITH_NO_RESPONSE_SQL ||= <<-SQL
WITH_NO_RESPONSE_SQL = <<-SQL
SELECT COUNT(*) as count, tt.created_at AS "date"
FROM (
SELECT t.id, t.created_at::date AS created_at, MIN(p.post_number) first_reply
@@ -1822,7 +1822,7 @@ class Topic < ActiveRecord::Base
builder.query_hash
end
WITH_NO_RESPONSE_TOTAL_SQL ||= <<-SQL
WITH_NO_RESPONSE_TOTAL_SQL = <<-SQL
SELECT COUNT(*) as count
FROM (
SELECT t.id, MIN(p.post_number) first_reply

View File

@@ -364,7 +364,7 @@ class User < ActiveRecord::Base
LAST_VISIT = -2
end
MAX_STAFF_DELETE_POST_COUNT ||= 5
MAX_STAFF_DELETE_POST_COUNT = 5
def self.user_tips
@user_tips ||=
@@ -1568,7 +1568,7 @@ class User < ActiveRecord::Base
result
end
USER_FIELD_PREFIX ||= "user_field_"
USER_FIELD_PREFIX = "user_field_"
def user_fields(field_ids = nil)
field_ids = (@all_user_field_ids ||= UserField.pluck(:id)) if field_ids.nil?
@@ -1711,7 +1711,7 @@ class User < ActiveRecord::Base
.pluck(:new_email)
end
RECENT_TIME_READ_THRESHOLD ||= 60.days
RECENT_TIME_READ_THRESHOLD = 60.days
def self.preload_recent_time_read(users)
times =

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
class UserSearch
MAX_SIZE_PRIORITY_MENTION ||= 500
MAX_SIZE_PRIORITY_MENTION = 500
def initialize(term, opts = {})
@term = term.downcase

View File

@@ -79,7 +79,7 @@ class UserSummary
user_counts(liked_users)
end
REPLY_ACTIONS ||= [UserAction::RESPONSE, UserAction::QUOTE, UserAction::MENTION]
REPLY_ACTIONS = [UserAction::RESPONSE, UserAction::QUOTE, UserAction::MENTION]
def most_replied_to_users
replied_users = {}

View File

@@ -40,10 +40,10 @@ class UsernameValidator
errors.empty?
end
CONFUSING_EXTENSIONS ||= /\.(js|json|css|htm|html|xml|jpg|jpeg|png|gif|bmp|ico|tif|tiff|woff)\z/i
MAX_CHARS ||= 60
CONFUSING_EXTENSIONS = /\.(js|json|css|htm|html|xml|jpg|jpeg|png|gif|bmp|ico|tif|tiff|woff)\z/i
MAX_CHARS = 60
ASCII_INVALID_CHAR_PATTERN ||= /[^\w.-]/
ASCII_INVALID_CHAR_PATTERN = /[^\w.-]/
# All Unicode characters except for alphabetic and numeric character, marks and underscores are invalid.
# In addition to that, the following letters and nonspacing marks are invalid:
# (U+034F) Combining Grapheme Joiner
@@ -56,7 +56,7 @@ class UsernameValidator
# (U+FFA0) Halfwidth Hangul Filler
# (U+FE00 - U+FE0F) "Variation Selectors" block
# (U+E0100 - U+E01EF) "Variation Selectors Supplement" block
UNICODE_INVALID_CHAR_PATTERN ||=
UNICODE_INVALID_CHAR_PATTERN =
/
[^\p{Alnum}\p{M}._-]|
[
@@ -72,9 +72,9 @@ class UsernameValidator
\p{In Variation Selectors Supplement}
]
/x
INVALID_LEADING_CHAR_PATTERN ||= /\A[^\p{Alnum}\p{M}_]+/
INVALID_TRAILING_CHAR_PATTERN ||= /[^\p{Alnum}\p{M}]+\z/
REPEATED_SPECIAL_CHAR_PATTERN ||= /[-_.]{2,}/
INVALID_LEADING_CHAR_PATTERN = /\A[^\p{Alnum}\p{M}_]+/
INVALID_TRAILING_CHAR_PATTERN = /[^\p{Alnum}\p{M}]+\z/
REPEATED_SPECIAL_CHAR_PATTERN = /[-_.]{2,}/
private