Class: MailyHerald::Mailer
- Inherits:
-
ActionMailer::Base
- Object
- ActionMailer::Base
- MailyHerald::Mailer
- Defined in:
- app/mailers/maily_herald/mailer.rb
Instance Attribute Summary collapse
-
#entity ⇒ Object
readonly
Returns the value of attribute entity.
Class Method Summary collapse
-
.deliver_mail(mail) ⇒ Object
TODO make it instance method so we get access to instance attributes.
Instance Method Summary collapse
Instance Attribute Details
#entity ⇒ Object (readonly)
Returns the value of attribute entity.
3 4 5 |
# File 'app/mailers/maily_herald/mailer.rb', line 3 def entity @entity end |
Class Method Details
.deliver_mail(mail) ⇒ Object
TODO make it instance method so we get access to instance attributes
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/mailers/maily_herald/mailer.rb', line 23 def deliver_mail(mail) #:nodoc: unless mail.maily_herald_data MailyHerald.logger.error("Unable to send message. Invalid mailing provided.") return end mailing = mail.maily_herald_data[:mailing] entity = mail.maily_herald_data[:entity] schedule = mail.maily_herald_data[:schedule] if !schedule && mailing.respond_to?(:schedule_delivery_to) # Implicitly create schedule for ad hoc delivery when called using Mailer.foo(entity).deliver syntax schedule = mail.maily_herald_data[:schedule] = mailing.schedule_delivery_to(entity) end if schedule mailing.send(:deliver_with_mailer, schedule) do ActiveSupport::Notifications.instrument("deliver.action_mailer") do |payload| self.set_payload_for_mail(payload, mail) yield # Let Mail do the delivery actions end mail end else MailyHerald.logger.log_processing(mailing, entity, mail, prefix: "Attempt to deliver email without schedule. No mail was sent", level: :debug) end end |
Instance Method Details
#generic(entity) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/mailers/maily_herald/mailer.rb', line 5 def generic entity destination = @maily_herald_mailing.destination(entity) subject = @maily_herald_mailing.render_subject(entity) content = @maily_herald_mailing.render_template(entity) opts = { to: destination, subject: subject } opts[:from] = @maily_herald_mailing.from if @maily_herald_mailing.from.present? mail(opts) do |format| format.text { render text: content } end end |
#mail(headers = {}, &block) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/mailers/maily_herald/mailer.rb', line 52 def mail(headers = {}, &block) return @_message if @_mail_was_called && headers.blank? && !block # Assign instance variables availabe for template if @_message.maily_herald_data @maily_subscription = @_message.maily_herald_data[:subscription] @maily_entity = @_message.maily_herald_data[:entity] @maily_mailing = @_message.maily_herald_data[:mailing] end super end |