Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the usage of instance variables from Noticed::Base #126

Merged
merged 1 commit into from
Jun 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions lib/noticed/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Base
class_attribute :delivery_methods, instance_writer: false, default: []
class_attribute :param_names, instance_writer: false, default: []

# Gives notifications access to the record and recipient when formatting for delivery
# Gives notifications access to the record and recipient during delivery
attr_accessor :record, :recipient

delegate :read?, :unread?, to: :record
Expand Down Expand Up @@ -71,22 +71,19 @@ def params
def run_delivery(recipient, enqueue: true)
delivery_methods = self.class.delivery_methods.dup

# Set recipient to instance var so it is available to Notification class
@recipient = recipient

# Run database delivery inline first if it exists so other methods have access to the record
if (index = delivery_methods.find_index { |m| m[:name] == :database })
delivery_method = delivery_methods.delete_at(index)
@record = run_delivery_method(delivery_method, recipient: recipient, enqueue: false)
record = run_delivery_method(delivery_method, recipient: recipient, enqueue: false, record: nil)
end

delivery_methods.each do |delivery_method|
run_delivery_method(delivery_method, recipient: recipient, enqueue: enqueue)
run_delivery_method(delivery_method, recipient: recipient, enqueue: enqueue, record: record)
end
end

# Actually runs an individual delivery
def run_delivery_method(delivery_method, recipient:, enqueue:)
def run_delivery_method(delivery_method, recipient:, enqueue:, record:)
args = {
notification_class: self.class.name,
options: delivery_method[:options],
Expand Down