Skip to content

Instantly share code, notes, and snippets.

@moofkit
Created February 3, 2023 16:33
Show Gist options
  • Save moofkit/2e51774e7d0d71948cc5fca53209f663 to your computer and use it in GitHub Desktop.
Save moofkit/2e51774e7d0d71948cc5fca53209f663 to your computer and use it in GitHub Desktop.
Rename Worker Class to Job
#!/usr/bin/env ruby
# frozen_string_literal: true
# https://juanitofatas.com/series/sidekiq/rename
files = Dir.glob("app/workers/**/*.rb")
puts "Found #{files.count} files"
files.each do |file|
content = File.read(file)
if match = content.match(/class (\S+)Worker/)
puts "Found #{match[1]}Worker"
content.gsub!(match[0], "class #{match[1]}Job")
addition = <<~ALIAS
#{match[1]}Worker = #{match[1]}Job
ALIAS
content += addition
File.write(file, content)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment