class BundleNotification::Deliver
Attributes
mailer_class[R]
Public Class Methods
new(mailer_class)
click to toggle source
# File lib/bundle_notification/deliver.rb, line 10 def initialize(mailer_class) @mailer_class = mailer_class end
Public Instance Methods
deliver_unsent_snippets()
click to toggle source
# File lib/bundle_notification/deliver.rb, line 14 def deliver_unsent_snippets Snippet.transaction do return if unsent_snippets.empty? unsent_snippets.group_by(&:recipient).each do |recipient, snippets| bundle_notify(recipient, snippets.map(&:data)).deliver_later end mark_snippets_sent end end
Private Instance Methods
bundle_notify(bundle_data, snippets_data)
click to toggle source
# File lib/bundle_notification/deliver.rb, line 26 def bundle_notify(bundle_data, snippets_data) mailer_class.constantize.bundle_notify(bundle_data, snippets_data) end
mark_snippets_sent()
click to toggle source
# File lib/bundle_notification/deliver.rb, line 34 def mark_snippets_sent Snippet.where(id: unsent_snippets).update_all(sent_at: (Time.zone || Time).now) @unsent_snippets = nil end
unsent_snippets()
click to toggle source
# File lib/bundle_notification/deliver.rb, line 30 def unsent_snippets @unsent_snippets ||= Snippet.unsent_for(mailer_class).order(:created_at, :id).lock.to_a end