From a29aa8db148d695d63641fccf71ab8534cc6fd36 Mon Sep 17 00:00:00 2001 From: Adam Ruzicka Date: Thu, 19 Sep 2024 13:42:17 +0200 Subject: [PATCH] Fix gettext:store_action_names The Object.const_source_location stopped being reliable since the zeitwerk changes landed. Each action is expected to define at least one of the three methods, so a source location of a method should be a reliable indicator of where the action comes from. --- lib/tasks/gettext.rake | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/tasks/gettext.rake b/lib/tasks/gettext.rake index b3c3b9ced..f883091b7 100644 --- a/lib/tasks/gettext.rake +++ b/lib/tasks/gettext.rake @@ -8,21 +8,27 @@ if gettext_find_task namespace :gettext do task :store_action_names => :environment do storage_file = "#{locale_path}/action_names.rb" - klasses = Actions::EntryAction - .subclasses - .uniq - .select do |action| - src, = Object.const_source_location(action.to_s) - src.start_with? @engine.root.to_s + method_names = [:plan, :run, :finalize] + instances = Actions::EntryAction + .descendants + .uniq + .map(&:allocate) + .select do |action| + method_names.any? do |method_name| + if action.respond_to?(method_name) + src, = action.method(method_name).source_location + src.start_with? @engine.root.to_s + end + end end - if klasses.any? + if instances.any? puts "writing action translations to: #{storage_file}" File.write storage_file, "# Autogenerated!\n" + - klasses - .map { |klass| %[_("#{klass.allocate.humanized_name}")] } + instances + .map { |instance| %[_("#{instance.humanized_name}")] } .sort .join("\n") + "\n" elsif File.exist? storage_file