Skip to content

Commit

Permalink
Maintenance: Move pre init code to files which get dynamically loaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgruner committed Mar 7, 2024
1 parent 5f0e542 commit 5d3d786
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
16 changes: 3 additions & 13 deletions config/application.rb
Expand Up @@ -12,21 +12,11 @@
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

# EmailAddress gem clashes with EmailAddress model.
# https://github.com/afair/email_address#namespace-conflict-resolution
EmailAddressValidator = EmailAddress
Object.send(:remove_const, :EmailAddress)

# Only load gems for asset compilation if they are needed to avoid
# having unneeded runtime dependencies like NodeJS.
if ArgvHelper.argv.any? { |e| e.start_with? 'assets:' } || Rails.groups.exclude?('production')
Bundler.load.current_dependencies.select do |dep|
require dep.name if dep.groups.include?(:assets)
end
# Initializers for before the app gets set up.
Pathname(__dir__).glob('pre_initializers/*.rb').each do |file|
require file
end

Zammad::SafeMode.hint

module Zammad
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
Expand Down
6 changes: 3 additions & 3 deletions config/initializers/core_ext.rb
@@ -1,8 +1,8 @@
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

# load all core_ext extensions
Rails.root.glob('lib/core_ext/**/*.rb').each do |file|
if File.file?(file)
Rails.root
.glob('lib/core_ext/**/*.rb')
.each do |file|
require file
end
end
6 changes: 6 additions & 0 deletions config/pre_initializers/email_address.rb
@@ -0,0 +1,6 @@
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

# EmailAddress gem clashes with EmailAddress model.
# https://github.com/afair/email_address#namespace-conflict-resolution
EmailAddressValidator = EmailAddress
Object.send(:remove_const, :EmailAddress)
12 changes: 12 additions & 0 deletions config/pre_initializers/load_asset_gems.rb
@@ -0,0 +1,12 @@
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

# Only load gems for asset compilation if they are needed to avoid
# having unneeded runtime dependencies like NodeJS.
if ArgvHelper.argv.any? { |e| e.start_with? 'assets:' } || Rails.groups.exclude?('production')
Bundler
.load
.current_dependencies
.each do |dep|
require dep.name if dep.groups.include?(:assets)
end
end
3 changes: 3 additions & 0 deletions config/pre_initializers/safe_mode.rb
@@ -0,0 +1,3 @@
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

Zammad::SafeMode.hint

0 comments on commit 5d3d786

Please sign in to comment.