Commit e0bc3447 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Configure Zeitwerk inflections

Adds Zeitwerk inflections to match current classes and adds a CI job
to ensure that our classes follow Zeitwerk conventions.
parent 43a11106
......@@ -251,6 +251,22 @@ static-analysis as-if-foss:
- .static-analysis:rules:as-if-foss
- .as-if-foss
zeitwerk-check:
extends:
- .rails-cache
- .default-before_script
- .rails:rules:ee-and-foss-unit
variables:
BUNDLE_WITHOUT: ""
SETUP_DB: "false"
needs: []
stage: test
script:
- sed -i -e "s/config\.autoloader = :classic/config\.autoloader = :zeitwerk/" config/application.rb
- RAILS_ENV=test bundle exec rake zeitwerk:check
- RAILS_ENV=development bundle exec rake zeitwerk:check
- RAILS_ENV=production bundle exec rake zeitwerk:check
rspec migration pg12:
extends:
- .rspec-base-pg12
......
......@@ -32,6 +32,8 @@ module Gitlab
require_dependency Rails.root.join('lib/gitlab/middleware/rack_multipart_tempfile_factory')
require_dependency Rails.root.join('lib/gitlab/runtime')
config.autoloader = :classic
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
......
......@@ -50,7 +50,7 @@ Rails.application.configure do
config.action_mailer.raise_delivery_errors = true
# Don't make a mess when bootstrapping a development environment
config.action_mailer.perform_deliveries = (ENV['BOOTSTRAP'] != '1')
config.action_mailer.preview_path = 'app/mailers/previews'
config.action_mailer.preview_path = "#{Rails.root}{/ee,}/app/mailers/previews"
config.eager_load = false
......
......@@ -7,7 +7,7 @@ rescue Gitlab::Runtime::IdentificationError => e
\n!! RUNTIME IDENTIFICATION FAILED: #{e}
Runtime based configuration settings may not work properly.
If you continue to see this error, please file an issue via
https://gitlab.com/gitlab-org/gitlab/issues/new
https://gitlab.com/gitlab-org/gitlab/-/issues/new
NOTICE
Gitlab::AppLogger.error(message)
Gitlab::ErrorTracking.track_exception(e)
......
# frozen_string_literal: true
GlobalID.prepend(Gitlab::Patch::GlobalID)
GlobalID.prepend(Gitlab::Patch::GlobalId)
# frozen_string_literal: true
Rails.autoloaders.each do |autoloader|
# We need to ignore these since these are non-Ruby files
# that do not define Ruby classes / modules
autoloader.ignore(Rails.root.join('lib/support'))
# Ignore generators since these are loaded manually by Rails
# https://github.com/rails/rails/blob/v6.1.3.2/railties/lib/rails/command/behavior.rb#L56-L65
autoloader.ignore(Rails.root.join('lib/generators'))
autoloader.ignore(Rails.root.join('ee/lib/generators')) if Gitlab.ee?
# Mailer previews are also loaded manually by Rails
# https://github.com/rails/rails/blob/v6.1.3.2/actionmailer/lib/action_mailer/preview.rb#L121-L125
autoloader.ignore(Rails.root.join('app/mailers/previews'))
autoloader.ignore(Rails.root.join('ee/app/mailers/previews')) if Gitlab.ee?
autoloader.inflector.inflect(
'api' => 'API',
'api_authentication' => 'APIAuthentication',
'api_guard' => 'APIGuard',
'group_api_compatibility' => 'GroupAPICompatibility',
'project_api_compatibility' => 'ProjectAPICompatibility',
'ast' => 'AST',
'cte' => 'CTE',
'recursive_cte' => 'RecursiveCTE',
'cidr' => 'CIDR',
'cli' => 'CLI',
'dn' => 'DN',
'global_id_type' => 'GlobalIDType',
'global_id_compatibility' => 'GlobalIDCompatibility',
'hll' => 'HLL',
'hll_redis_counter' => 'HLLRedisCounter',
'redis_hll_metric' => 'RedisHLLMetric',
'hmac_token' => 'HMACToken',
'html' => 'HTML',
'html_parser' => 'HTMLParser',
'html_gitlab' => 'HTMLGitlab',
'http' => 'HTTP',
'http_connection_adapter' => 'HTTPConnectionAdapter',
'http_clone_enabled_check' => 'HTTPCloneEnabledCheck',
'hangouts_chat_http_override' => 'HangoutsChatHTTPOverride',
'chunked_io' => 'ChunkedIO',
'http_io' => 'HttpIO',
'json_formatter' => 'JSONFormatter',
'json_web_token' => 'JSONWebToken',
'as_json' => 'AsJSON',
'jwt_token' => 'JWTToken',
'ldap_key' => 'LDAPKey',
'mr_note' => 'MRNote',
'pdf' => 'PDF',
'rsa_token' => 'RSAToken',
'san_extension' => 'SANExtension',
'sca' => 'SCA',
'spdx' => 'SPDX',
'sql' => 'SQL',
'sse_helpers' => 'SSEHelpers',
'ssh_key' => 'SSHKey',
'ssh_key_with_user' => 'SSHKeyWithUser',
'ssh_public_key' => 'SSHPublicKey',
'git_ssh_proxy' => 'GitSSHProxy',
'git_user_default_ssh_config_check' => 'GitUserDefaultSSHConfigCheck',
'binary_stl' => 'BinarySTL',
'text_stl' => 'TextSTL',
'svg' => 'SVG',
'function_uri' => 'FunctionURI',
'uuid' => 'UUID',
'vulnerability_uuid' => 'VulnerabilityUUID',
'vs_code_extension_activity_unique_counter' => 'VSCodeExtensionActivityUniqueCounter'
)
end
......@@ -4,7 +4,7 @@
# we alter GlobalID so it will correctly find the record with its new model name.
module Gitlab
module Patch
module GlobalID
module GlobalId
def initialize(gid, options = {})
super
......
......@@ -3,8 +3,8 @@
require 'spec_helper'
RSpec.describe 'global_id' do
it 'prepends `Gitlab::Patch::GlobalID`' do
expect(GlobalID.ancestors).to include(Gitlab::Patch::GlobalID)
it 'prepends `Gitlab::Patch::GlobalId`' do
expect(GlobalID.ancestors).to include(Gitlab::Patch::GlobalId)
end
it 'patches GlobalID to find aliased models when a deprecation exists' do
......
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