Unable resolve mailer class different to pattern name.gsub(/Delivery$/, "Mailer")
brovikov opened this issue · comments
I faced with problem when I need to notify by email several recipients with different content. So I have several Action Mailer classes for that. But I couldn't find a way how to explicitly set mailer class when I'm registering the line. It would be great to have it on the same way how we do it with ActiveDelivery::Lines::Notifier
:
register_line :merchant, ActiveDelivery::Lines::Notifier,
resolver: ->(name) { Notifications::MerchantMailer }
To have it working - I added CustomMailer
class:
module DeliveryLines
class CustomMailer < ActiveDelivery::Lines::Notifier
alias mailer_class handler_class
def notify?(method_name)
mailer_class.action_methods.include?(method_name.to_s)
end
def notify_now(mailer, mid, *args)
mailer.public_send(mid, *args).deliver_now
end
def notify_later(mailer, mid, *args)
mailer.public_send(mid, *args).deliver_later
end
end
end
It works good to me. But probably having ability to set resolver for ActiveDelivery::Lines::Mailer
class on the same way how we have it at ActiveDelivery::Lines::Notifier
is a good idea for improvement?
having ability to set resolver for ActiveDelivery::Lines::Mailer class on the same way how we have it at ActiveDelivery::Lines::Notifier is a good idea for improvement?
Sounds like a good idea to me. We can go even further and move the resolving logic to ActiveDelivery::Lines::Base
(I mean, #resolve_class
method and resolver
option).
Would you like to propose a PR?
Yep, I'll send PR. Thanks!