Sha256: 373715bbee4d73908b877995a7007bc217624207d3ac689e46cdcbcc62d4fd6c

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
composable-pwdless-0.0.12 app/mailers/composable/pwdless/mailer.rb
composable-pwdless-0.0.11 app/mailers/composable/pwdless/mailer.rb
composable-pwdless-0.0.10 app/mailers/composable/pwdless/mailer.rb