From cb477149c483e9a24d01aa2cf0f39b067674f998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sun, 17 Mar 2024 21:35:17 +0100 Subject: [PATCH] Move lib folder inside the app folder The purpose of the lib folder is to have code that doesn't necessary belong in the application but can be shared with other applications. However, we don't have other applications and, if we did, the way to share code between them would be using a gem or even a git submodule. So having both the `app/` and the `lib/` folders is confusing IMHO, and it causes unnecessary problems with autoloading. So we're moving the `lib/` folder to `app/lib/`. Originally, some of these files were in the `app/services/` folder and then they were moved to the `lib/` folder. We're using `app/lib/` instead of `app/services/` so the upgrade is less confusing. There's an exception, though. The `OmniAuth::Strategies::Wordpress` class needs to be available in the Devise initializer. Since this is an initializer and trying to autoload a class here will be problematic when switching to Zeitwerk, we'll keep the `require` clause on top of the Devise initializer in order to load the file and so it will be loaded even if it isn't in the autoload paths anymore. --- .rubocop.yml | 4 ++-- {lib => app/lib}/active_model/dates.rb | 0 .../lib}/active_storage/service/tenant_disk_service.rb | 0 {lib => app/lib}/acts_as_paranoid_aliases.rb | 0 {lib => app/lib}/admin_legislation_sanitizer.rb | 0 {lib => app/lib}/admin_wysiwyg_sanitizer.rb | 0 {lib => app/lib}/age.rb | 0 {lib => app/lib}/application_logger.rb | 0 {lib => app/lib}/application_responder.rb | 0 {lib => app/lib}/asset_finder.rb | 0 {lib => app/lib}/authentication_logger.rb | 0 {lib => app/lib}/census_api.rb | 0 {lib => app/lib}/census_caller.rb | 0 {lib => app/lib}/ckeditor/backend/active_storage.rb | 0 {lib => app/lib}/comment_tree.rb | 0 {lib => app/lib}/consul_form_builder.rb | 0 {lib => app/lib}/document_parser.rb | 0 {lib => app/lib}/email_digest.rb | 0 {lib => app/lib}/evaluation_comment_email.rb | 0 {lib => app/lib}/geozone_stats.rb | 0 {lib => app/lib}/local_census.rb | 0 {lib => app/lib}/manager_authenticator.rb | 0 {lib => app/lib}/markdown_converter.rb | 0 {lib => app/lib}/merged_comment_tree.rb | 0 {lib => app/lib}/omniauth_tenant_setup.rb | 0 {lib => app/lib}/percentage_calculator.rb | 0 {lib => app/lib}/remote_census_api.rb | 0 {lib => app/lib}/remote_translations/caller.rb | 0 .../lib}/remote_translations/microsoft/available_locales.rb | 0 {lib => app/lib}/remote_translations/microsoft/client.rb | 0 .../lib}/remote_translations/microsoft/sentences_parser.rb | 0 {lib => app/lib}/reply_email.rb | 0 {lib => app/lib}/score_calculator.rb | 0 {lib => app/lib}/search_dictionary_selector.rb | 0 {lib => app/lib}/sms_api.rb | 0 {lib => app/lib}/tag_sanitizer.rb | 0 {lib => app/lib}/user_segments.rb | 0 {lib => app/lib}/wysiwyg_sanitizer.rb | 0 config/application.rb | 2 -- config/environments/production.rb | 5 ----- 40 files changed, 2 insertions(+), 9 deletions(-) rename {lib => app/lib}/active_model/dates.rb (100%) rename {lib => app/lib}/active_storage/service/tenant_disk_service.rb (100%) rename {lib => app/lib}/acts_as_paranoid_aliases.rb (100%) rename {lib => app/lib}/admin_legislation_sanitizer.rb (100%) rename {lib => app/lib}/admin_wysiwyg_sanitizer.rb (100%) rename {lib => app/lib}/age.rb (100%) rename {lib => app/lib}/application_logger.rb (100%) rename {lib => app/lib}/application_responder.rb (100%) rename {lib => app/lib}/asset_finder.rb (100%) rename {lib => app/lib}/authentication_logger.rb (100%) rename {lib => app/lib}/census_api.rb (100%) rename {lib => app/lib}/census_caller.rb (100%) rename {lib => app/lib}/ckeditor/backend/active_storage.rb (100%) rename {lib => app/lib}/comment_tree.rb (100%) rename {lib => app/lib}/consul_form_builder.rb (100%) rename {lib => app/lib}/document_parser.rb (100%) rename {lib => app/lib}/email_digest.rb (100%) rename {lib => app/lib}/evaluation_comment_email.rb (100%) rename {lib => app/lib}/geozone_stats.rb (100%) rename {lib => app/lib}/local_census.rb (100%) rename {lib => app/lib}/manager_authenticator.rb (100%) rename {lib => app/lib}/markdown_converter.rb (100%) rename {lib => app/lib}/merged_comment_tree.rb (100%) rename {lib => app/lib}/omniauth_tenant_setup.rb (100%) rename {lib => app/lib}/percentage_calculator.rb (100%) rename {lib => app/lib}/remote_census_api.rb (100%) rename {lib => app/lib}/remote_translations/caller.rb (100%) rename {lib => app/lib}/remote_translations/microsoft/available_locales.rb (100%) rename {lib => app/lib}/remote_translations/microsoft/client.rb (100%) rename {lib => app/lib}/remote_translations/microsoft/sentences_parser.rb (100%) rename {lib => app/lib}/reply_email.rb (100%) rename {lib => app/lib}/score_calculator.rb (100%) rename {lib => app/lib}/search_dictionary_selector.rb (100%) rename {lib => app/lib}/sms_api.rb (100%) rename {lib => app/lib}/tag_sanitizer.rb (100%) rename {lib => app/lib}/user_segments.rb (100%) rename {lib => app/lib}/wysiwyg_sanitizer.rb (100%) diff --git a/.rubocop.yml b/.rubocop.yml index b81f69685..61a117f97 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -10,7 +10,7 @@ AllCops: DisplayStyleGuide: true Exclude: - "db/schema.rb" - - "lib/ckeditor/backend/active_storage.rb" + - "app/lib/ckeditor/backend/active_storage.rb" DisabledByDefault: true Bundler/DuplicatedGem: @@ -480,7 +480,7 @@ Rails/SkipsModelValidations: - update_attribute Exclude: - app/models/tenant.rb - - lib/acts_as_paranoid_aliases.rb + - app/lib/acts_as_paranoid_aliases.rb Rails/TimeZone: Enabled: true diff --git a/lib/active_model/dates.rb b/app/lib/active_model/dates.rb similarity index 100% rename from lib/active_model/dates.rb rename to app/lib/active_model/dates.rb diff --git a/lib/active_storage/service/tenant_disk_service.rb b/app/lib/active_storage/service/tenant_disk_service.rb similarity index 100% rename from lib/active_storage/service/tenant_disk_service.rb rename to app/lib/active_storage/service/tenant_disk_service.rb diff --git a/lib/acts_as_paranoid_aliases.rb b/app/lib/acts_as_paranoid_aliases.rb similarity index 100% rename from lib/acts_as_paranoid_aliases.rb rename to app/lib/acts_as_paranoid_aliases.rb diff --git a/lib/admin_legislation_sanitizer.rb b/app/lib/admin_legislation_sanitizer.rb similarity index 100% rename from lib/admin_legislation_sanitizer.rb rename to app/lib/admin_legislation_sanitizer.rb diff --git a/lib/admin_wysiwyg_sanitizer.rb b/app/lib/admin_wysiwyg_sanitizer.rb similarity index 100% rename from lib/admin_wysiwyg_sanitizer.rb rename to app/lib/admin_wysiwyg_sanitizer.rb diff --git a/lib/age.rb b/app/lib/age.rb similarity index 100% rename from lib/age.rb rename to app/lib/age.rb diff --git a/lib/application_logger.rb b/app/lib/application_logger.rb similarity index 100% rename from lib/application_logger.rb rename to app/lib/application_logger.rb diff --git a/lib/application_responder.rb b/app/lib/application_responder.rb similarity index 100% rename from lib/application_responder.rb rename to app/lib/application_responder.rb diff --git a/lib/asset_finder.rb b/app/lib/asset_finder.rb similarity index 100% rename from lib/asset_finder.rb rename to app/lib/asset_finder.rb diff --git a/lib/authentication_logger.rb b/app/lib/authentication_logger.rb similarity index 100% rename from lib/authentication_logger.rb rename to app/lib/authentication_logger.rb diff --git a/lib/census_api.rb b/app/lib/census_api.rb similarity index 100% rename from lib/census_api.rb rename to app/lib/census_api.rb diff --git a/lib/census_caller.rb b/app/lib/census_caller.rb similarity index 100% rename from lib/census_caller.rb rename to app/lib/census_caller.rb diff --git a/lib/ckeditor/backend/active_storage.rb b/app/lib/ckeditor/backend/active_storage.rb similarity index 100% rename from lib/ckeditor/backend/active_storage.rb rename to app/lib/ckeditor/backend/active_storage.rb diff --git a/lib/comment_tree.rb b/app/lib/comment_tree.rb similarity index 100% rename from lib/comment_tree.rb rename to app/lib/comment_tree.rb diff --git a/lib/consul_form_builder.rb b/app/lib/consul_form_builder.rb similarity index 100% rename from lib/consul_form_builder.rb rename to app/lib/consul_form_builder.rb diff --git a/lib/document_parser.rb b/app/lib/document_parser.rb similarity index 100% rename from lib/document_parser.rb rename to app/lib/document_parser.rb diff --git a/lib/email_digest.rb b/app/lib/email_digest.rb similarity index 100% rename from lib/email_digest.rb rename to app/lib/email_digest.rb diff --git a/lib/evaluation_comment_email.rb b/app/lib/evaluation_comment_email.rb similarity index 100% rename from lib/evaluation_comment_email.rb rename to app/lib/evaluation_comment_email.rb diff --git a/lib/geozone_stats.rb b/app/lib/geozone_stats.rb similarity index 100% rename from lib/geozone_stats.rb rename to app/lib/geozone_stats.rb diff --git a/lib/local_census.rb b/app/lib/local_census.rb similarity index 100% rename from lib/local_census.rb rename to app/lib/local_census.rb diff --git a/lib/manager_authenticator.rb b/app/lib/manager_authenticator.rb similarity index 100% rename from lib/manager_authenticator.rb rename to app/lib/manager_authenticator.rb diff --git a/lib/markdown_converter.rb b/app/lib/markdown_converter.rb similarity index 100% rename from lib/markdown_converter.rb rename to app/lib/markdown_converter.rb diff --git a/lib/merged_comment_tree.rb b/app/lib/merged_comment_tree.rb similarity index 100% rename from lib/merged_comment_tree.rb rename to app/lib/merged_comment_tree.rb diff --git a/lib/omniauth_tenant_setup.rb b/app/lib/omniauth_tenant_setup.rb similarity index 100% rename from lib/omniauth_tenant_setup.rb rename to app/lib/omniauth_tenant_setup.rb diff --git a/lib/percentage_calculator.rb b/app/lib/percentage_calculator.rb similarity index 100% rename from lib/percentage_calculator.rb rename to app/lib/percentage_calculator.rb diff --git a/lib/remote_census_api.rb b/app/lib/remote_census_api.rb similarity index 100% rename from lib/remote_census_api.rb rename to app/lib/remote_census_api.rb diff --git a/lib/remote_translations/caller.rb b/app/lib/remote_translations/caller.rb similarity index 100% rename from lib/remote_translations/caller.rb rename to app/lib/remote_translations/caller.rb diff --git a/lib/remote_translations/microsoft/available_locales.rb b/app/lib/remote_translations/microsoft/available_locales.rb similarity index 100% rename from lib/remote_translations/microsoft/available_locales.rb rename to app/lib/remote_translations/microsoft/available_locales.rb diff --git a/lib/remote_translations/microsoft/client.rb b/app/lib/remote_translations/microsoft/client.rb similarity index 100% rename from lib/remote_translations/microsoft/client.rb rename to app/lib/remote_translations/microsoft/client.rb diff --git a/lib/remote_translations/microsoft/sentences_parser.rb b/app/lib/remote_translations/microsoft/sentences_parser.rb similarity index 100% rename from lib/remote_translations/microsoft/sentences_parser.rb rename to app/lib/remote_translations/microsoft/sentences_parser.rb diff --git a/lib/reply_email.rb b/app/lib/reply_email.rb similarity index 100% rename from lib/reply_email.rb rename to app/lib/reply_email.rb diff --git a/lib/score_calculator.rb b/app/lib/score_calculator.rb similarity index 100% rename from lib/score_calculator.rb rename to app/lib/score_calculator.rb diff --git a/lib/search_dictionary_selector.rb b/app/lib/search_dictionary_selector.rb similarity index 100% rename from lib/search_dictionary_selector.rb rename to app/lib/search_dictionary_selector.rb diff --git a/lib/sms_api.rb b/app/lib/sms_api.rb similarity index 100% rename from lib/sms_api.rb rename to app/lib/sms_api.rb diff --git a/lib/tag_sanitizer.rb b/app/lib/tag_sanitizer.rb similarity index 100% rename from lib/tag_sanitizer.rb rename to app/lib/tag_sanitizer.rb diff --git a/lib/user_segments.rb b/app/lib/user_segments.rb similarity index 100% rename from lib/user_segments.rb rename to app/lib/user_segments.rb diff --git a/lib/wysiwyg_sanitizer.rb b/app/lib/wysiwyg_sanitizer.rb similarity index 100% rename from lib/wysiwyg_sanitizer.rb rename to app/lib/wysiwyg_sanitizer.rb diff --git a/config/application.rb b/config/application.rb index a2cf9bfde..6b6d6c51d 100644 --- a/config/application.rb +++ b/config/application.rb @@ -125,8 +125,6 @@ module Consul config.assets.paths << Rails.root.join("node_modules", "jquery-ui", "themes", "base") config.assets.paths << Rails.root.join("node_modules") - # Add lib to the autoload path - config.autoload_paths << Rails.root.join("lib") config.active_job.queue_adapter = :delayed_job # CONSUL DEMOCRACY specific custom overrides diff --git a/config/environments/production.rb b/config/environments/production.rb index 1b200d1ab..57ba25c25 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -12,11 +12,6 @@ Rails.application.configure do # Rake tasks automatically ignore this option for performance. config.eager_load = true - # Because autoloading is disabled in production environments with Rails 5, - # using autoload_paths will not load needed classes from specified paths. - # The solution to this, is to ask Rails to eager load classes. - config.eager_load_paths += ["#{config.root}/lib"] - # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true