File: email.rb

package info (click to toggle)
ruby-noticed 3.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 324 kB
  • sloc: ruby: 1,186; makefile: 4
file content (27 lines) | stat: -rw-r--r-- 812 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module Noticed
  module DeliveryMethods
    class Email < DeliveryMethod
      required_options :mailer, :method

      def deliver
        mailer = fetch_constant(:mailer)
        email = evaluate_option(:method)
        args = evaluate_option(:args) || []
        kwargs = evaluate_option(:kwargs) || {}
        mail = mailer.with(params).public_send(email, *args, **kwargs)

        (!!evaluate_option(:enqueue)) ? mail.deliver_later : mail.deliver_now
      end

      def params
        (evaluate_option(:params) || notification&.params || {}).merge(
          notification: notification,
          record: notification&.record,
          recipient: notification&.recipient
        )
      end
    end
  end
end

ActiveSupport.run_load_hooks :noticed_delivery_methods_email, Noticed::DeliveryMethods::Email