Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Zeitwerk loader support #62

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
fail-fast: false
matrix:
foreman:
- 3.9-stable
- develop
uses: theforeman/actions/.github/workflows/foreman_plugin.yml@v0
with:
Expand Down
6 changes: 3 additions & 3 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Layout/FirstHashElementIndentation:
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
Layout/HashAlignment:
Exclude:
- 'lib/foreman_theme_satellite/branded_words.rb'
- 'lib/foreman_theme_satellite/foreman_brand.rb'

# Offense count: 1
# Cop supports --auto-correct.
Expand Down Expand Up @@ -139,7 +139,7 @@ Layout/SpaceAfterComma:
Layout/SpaceAroundOperators:
Exclude:
- 'app/overrides/bootdisk_help_page.rb'
- 'lib/foreman_theme_satellite/branded_words.rb'
- 'lib/foreman_theme_satellite/foreman_brand.rb'
- 'lib/foreman_theme_satellite/engine.rb'
- 'lib/generators/foreman_theme_satellite/lib/css_compare.rb'

Expand Down Expand Up @@ -409,7 +409,7 @@ Style/TrailingCommaInHashLiteral:
Exclude:
- 'app/models/concerns/provisioning.rb'
- 'app/services/concerns/setting_registry_branding.rb'
- 'lib/foreman_theme_satellite/branded_words.rb'
- 'lib/foreman_theme_satellite/foreman_brand.rb'
- 'lib/foreman_theme_satellite/deprecated_templates.rb'
- 'lib/foreman_theme_satellite/documentation.rb'
- 'lib/foreman_theme_satellite/engine.rb'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const SettingName = ({ setting }) => (

In case there is a need to add more terms to be branded **or bypass branding**,
it can be done in
[`branded_words.rb`](https://github.com/RedHatSatellite/foreman_theme_satellite/blob/develop/lib/foreman_theme_satellite/branded_words.rb).
[`foreman_brand.rb`](https://github.com/RedHatSatellite/foreman_theme_satellite/blob/develop/lib/foreman_theme_satellite/foreman_brand.rb).
This is a dictionary where the key is a
[Regular Expression](https://regex101.com/) and the value is a replacement
string.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% require_relative '../../../lib/foreman_theme_satellite/branded_words' %>
<% require_relative '../../../lib/foreman_theme_satellite/foreman_brand' %>

var branded_words = []
<% ForemanThemeSatellite::FOREMAN_BRAND.map do |exp, replace| %>
Expand Down
6 changes: 6 additions & 0 deletions config/initializers/inflections.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Rails.autoloaders.each do |autoloader|
autoloader.inflector.inflect(
'foreman_brand' => 'FOREMAN_BRAND',
'deprecated_templates' => 'DEPRECATED_TEMPLATES'
)
end
4 changes: 4 additions & 0 deletions config/initializers/zeitwerk.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Rails.autoloaders.main.ignore(
ForemanThemeSatellite::Engine.root.join('lib/generators'),
ForemanThemeSatellite::Engine.root.join('lib/foreman_theme_satellite/version.rb')
)
2 changes: 1 addition & 1 deletion db/migrate/20181108171732_change_blog_url.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ChangeBlogUrl < ActiveRecord::Migration[5.1]
class ChangeBlogURL < ActiveRecord::Migration[5.1]
def up
if Setting[:rss_url] == 'https://access.redhat.com/blogs/1169563/feed'
Setting[:rss_url] = 'https://www.redhat.com/en/rss/blog/channel/red-hat-satellite'
Expand Down
27 changes: 5 additions & 22 deletions lib/foreman_theme_satellite/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,11 @@
module ForemanThemeSatellite
class Engine < ::Rails::Engine
engine_name 'foreman_theme_satellite'

config.eager_load_paths += Dir["#{config.root}/app/overrides"]
config.eager_load_paths += Dir["#{config.root}/app/controllers/concerns"]
config.eager_load_paths += Dir["#{config.root}/app/helpers"]
config.eager_load_paths += Dir["#{config.root}/app/models/concerns"]
config.eager_load_paths += Dir["#{config.root}/app/services/concerns"]
config.eager_load_paths += Dir["#{config.root}/lib/foreman_theme_satellite"]

initializer 'foreman_theme_satellite.load_default_settings', :before => :load_config_initializers do |app|
SettingRegistry.prepend SettingRegistryBranding
end
config.eager_load_paths += Dir["#{config.root}/lib"]

initializer 'foreman_theme_satellite.register_plugin', :before=> :finisher_hook do |app|
Foreman::Plugin.register :foreman_theme_satellite do
requires_foreman '>= 3.7.0'
requires_foreman '>= 3.13.0'
evgeni marked this conversation as resolved.
Show resolved Hide resolved
register_gettext

settings do
Expand All @@ -36,7 +26,7 @@ class Engine < ::Rails::Engine
end
end

tests_to_skip ({
tests_to_skip ({
"ComputeResourceTest" => ["friendly provider name"],
"RealmIntegrationTest" => ["create new page"],
"SmartProxyIntegrationTest" => ["create new page", "index page"],
Expand All @@ -49,7 +39,7 @@ class Engine < ::Rails::Engine
"OrganizationTest" => ["should clone organization with all associations"],
"RealmTest" => ["realm can be assigned to locations"],
"LocationTest" => ["should clone location with all associations"]
})
})

extend_rabl_template 'api/v2/home/status', 'api/v2/home/status_extensions'
extend_template_helpers ForemanThemeSatellite::RendererMethods
Expand All @@ -69,19 +59,12 @@ class Engine < ::Rails::Engine
end
end

initializer 'foreman_theme_satellite.rails_loading_workaround' do
# Without this, in production environment the module gets prepended too
# late and the extensions do not get applied
# the idea is stolen from https://github.com/theforeman/foreman_remote_execution/commit/2efd0a6eccfc19e282f453d5629cf46e729963eb
ProvisioningTemplatesHelper.prepend ProvisioningTemplatesHelperBranding
end

# Include concerns in this config.to_prepare block
config.to_prepare do
begin
SettingRegistry.prepend SettingRegistryBranding
# Include your monkey-patches over here
::ForemanGoogle::GCE.send(:prepend, GCE::ClassMethods) if Foreman::Plugin.installed?("foreman_google")
require 'rss_checker_branding'
UINotifications::RssNotificationsChecker.send :prepend, RssCheckerBranding
Foreman::Model::Openstack.send :include, Openstack
Foreman::Model::Ovirt.send :include, Ovirt
Expand Down
1 change: 0 additions & 1 deletion lib/foreman_theme_satellite/replacer_repository.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'fast_gettext'
require_relative 'branded_words'

module ForemanThemeSatellite
# This repository is a wrapper above other repository,
Expand Down
4 changes: 3 additions & 1 deletion test/link_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def navigate_path(path, hash = @toc)

inner_hash = hash[first]

return inner_hash if rest.empty?
# rubocop:disable Rails/Blank
return inner_hash if rest.nil? || rest.empty?
# rubocop:enable Rails/Blank

navigate_path(rest, inner_hash)
end
Expand Down