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 Sep 19, 2024
1 parent d3e91d8 commit 91c2232
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lib/tasks/gettext.rake
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@ 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
instances = Actions::EntryAction
.subclasses
.uniq
.map(&:allocate)
.select do |action|
[:plan, :run, :finalize].any? do |method_name|

Check failure on line 16 in lib/tasks/gettext.rake

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Performance/CollectionLiteralInLoop: Avoid immutable Array literals in loops. It is better to extract it into a local variable or a constant.
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 91c2232

Please sign in to comment.