Skip to content

Commit

Permalink
Remove instance variables (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
manojmj92 authored Jun 1, 2021
1 parent 66d47aa commit e33aa24
Showing 1 changed file with 4 additions and 7 deletions.
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

0 comments on commit e33aa24

Please sign in to comment.