Skip to content

Commit

Permalink
Fix gettext:store_action_names
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
adamruzicka committed Oct 15, 2024
1 parent d3e91d8 commit a29aa8d
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/tasks/gettext.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a29aa8d

Please sign in to comment.