From e23c31195b097223f030800614b55d09bf54d086 Mon Sep 17 00:00:00 2001 From: Linca <41134017+Lhcfl@users.noreply.github.com> Date: Wed, 28 Aug 2024 11:36:44 +0800 Subject: [PATCH] DEV: Use Rails autoloading (#321) This commit enables Rails autoloading for Data Explorer. See: https://meta.discourse.org/t/structuring-a-plugin-for-rails-autoloading/256092 --- lib/discourse_data_explorer/engine.rb | 3 +++ lib/{ => discourse_data_explorer}/report_generator.rb | 0 .../result_format_converter.rb | 0 lib/{ => discourse_data_explorer}/result_to_markdown.rb | 0 plugin.rb | 9 --------- 5 files changed, 3 insertions(+), 9 deletions(-) rename lib/{ => discourse_data_explorer}/report_generator.rb (100%) rename lib/{ => discourse_data_explorer}/result_format_converter.rb (100%) rename lib/{ => discourse_data_explorer}/result_to_markdown.rb (100%) diff --git a/lib/discourse_data_explorer/engine.rb b/lib/discourse_data_explorer/engine.rb index 5da807a..0b42330 100644 --- a/lib/discourse_data_explorer/engine.rb +++ b/lib/discourse_data_explorer/engine.rb @@ -4,5 +4,8 @@ module ::DiscourseDataExplorer class Engine < ::Rails::Engine engine_name PLUGIN_NAME isolate_namespace DiscourseDataExplorer + config.autoload_paths << File.join(config.root, "lib") + scheduled_job_dir = "#{config.root}/app/jobs/scheduled" + config.to_prepare { Rails.autoloaders.main.eager_load_dir(scheduled_job_dir) } end end diff --git a/lib/report_generator.rb b/lib/discourse_data_explorer/report_generator.rb similarity index 100% rename from lib/report_generator.rb rename to lib/discourse_data_explorer/report_generator.rb diff --git a/lib/result_format_converter.rb b/lib/discourse_data_explorer/result_format_converter.rb similarity index 100% rename from lib/result_format_converter.rb rename to lib/discourse_data_explorer/result_format_converter.rb diff --git a/lib/result_to_markdown.rb b/lib/discourse_data_explorer/result_to_markdown.rb similarity index 100% rename from lib/result_to_markdown.rb rename to lib/discourse_data_explorer/result_to_markdown.rb diff --git a/plugin.rb b/plugin.rb index d62981d..6f74277 100644 --- a/plugin.rb +++ b/plugin.rb @@ -32,12 +32,6 @@ end require_relative "lib/discourse_data_explorer/engine" after_initialize do - require_relative "app/jobs/scheduled/delete_hidden_queries" - require_relative "lib/discourse_data_explorer/data_explorer" - require_relative "lib/discourse_data_explorer/parameter" - require_relative "lib/discourse_data_explorer/queries" - require_relative "lib/discourse_data_explorer/query_group_bookmarkable" - GlobalSetting.add_default(:max_data_explorer_api_reqs_per_10_seconds, 2) # Available options: @@ -77,9 +71,6 @@ after_initialize do { run_queries: { actions: %w[discourse_data_explorer/query#run], params: %i[id] } }, ) - require_relative "lib/report_generator" - require_relative "lib/result_to_markdown" - require_relative "lib/result_format_converter" reloadable_patch do if defined?(DiscourseAutomation) add_automation_scriptable("recurring_data_explorer_result_pm") do