module Composable module Pwdless class Mailer < Pwdless.parent_mailer.constantize def notification_email @authentication = params[:authentication] @code = @authentication.code mail headers_for(:notification_email, to: @authentication.email) end private def headers_for(action, options) @headers ||= { subject: subject_for(action), from: mailer_sender, reply_to: mailer_reply_to, template_path: Pwdless.mailer_template_path, template_name: action }.merge(options) end def mailer_reply_to mailer_sender(:reply_to) end def mailer_from mailer_sender(:from) end def mailer_sender(sender = :from) default_sender = default_params[sender] if default_sender.present? default_sender.respond_to?(:to_proc) ? instance_eval(&default_sender) : default_sender elsif Pwdless.mailer_sender.is_a?(Proc) Pwdless.mailer_sender.call else Pwdless.mailer_sender end end def subject_for(key) Pwdless.t(:subject, scope: "mailer.#{key}", code: @code) end end end end