Last active
August 8, 2017 09:42
-
-
Save glebm/5725347 to your computer and use it in GitHub Desktop.
Inject locale into Resque::Mailer and Devise::Async
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'resque_mailer' | |
require 'devise/async' | |
# pop and set locale from the args before running | |
module PerformWithLocale | |
def perform(*args) | |
I18n.with_locale(args.pop) do | |
super(*args) | |
end | |
end | |
end | |
module DeliverWithLocale | |
def deliver | |
# @args are not used when rendered inline, only when enqueueing | |
@args << I18n.locale.to_s | |
super | |
end | |
end | |
#= resque_mailer locale support | |
if defined?(Resque::Mailer) | |
module Resque::Mailer | |
# push locale onto the args when queueing | |
MessageDecoy.send :prepend, DeliverWithLocale | |
# pop when dequeueing | |
ClassMethods.send :prepend, PerformWithLocale | |
end | |
end | |
#= devise/async locale support | |
if defined?(Devise::Async) | |
module Devise::Async | |
module EnqueueWithLocale | |
def enqueue(*args) | |
super *(args + [I18n.locale]) | |
end | |
end | |
class Worker | |
class << self | |
prepend Devise::Async::EnqueueWithLocale | |
end | |
end | |
class Backend::Resque | |
class << self | |
prepend PerformWithLocale | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
requires ruby 2 and this devise-async PR mhfs/devise-async#37