Skip to content

Commit

Permalink
Merge pull request #1 from challengepost/remove-settings
Browse files Browse the repository at this point in the history
configurable interceptor email and remove Settings depedency
  • Loading branch information
devpost-mzheng authored Jan 11, 2019
2 parents 55ce950 + 0bb02cf commit c74217e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/courrier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require "courrier/envelope"
require "courrier/email"
require "courrier/configuration"
require "courrier/notifier"

module Courrier
class << self
Expand Down
1 change: 1 addition & 0 deletions lib/courrier/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Courrier
class Configuration
attr_accessor :mailer
attr_accessor :interceptor_email
end
end
2 changes: 1 addition & 1 deletion lib/courrier/email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def self.subclass_by_email_name(email_name)
end

def recipient
return Settings.interceptor_emails.first if Settings.interceptor_emails.any?
return Courrier.configuration.interceptor_email if Courrier.configuration.interceptor_email.present?
method = self.class.recipient_method
raise Courrier::RecipientUndefinedError.new("Please declare a recipient in #{self.class.name}") if method.nil? || !self.respond_to?(method, true)
send(method)
Expand Down
10 changes: 6 additions & 4 deletions lib/courrier/envelope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ def deliver
log "Delivering #{email_name} to #{recipient_email}"
payload.tap do |args|

case recipient
when User
if emailable?(recipient)
Courrier.configuration.mailer.transactional_email_to_user(*args)
else
Courrier.configuration.mailer.transactional_email_to_address(*args)
Expand All @@ -35,8 +34,7 @@ def mailer
end

def recipient_email
case recipient
when User
if emailable?(recipient)
recipient.email
else
recipient
Expand All @@ -51,5 +49,9 @@ def log(info)
Rails.logger.info "#{self.class.name} -- #{info}"
end

def emailable?(recipient)
recipient.respond_to? :email
end

end
end
18 changes: 18 additions & 0 deletions lib/courrier/notifier.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Courrier
module Notifier
extend self

def deliver(*args)
Courrier::Envelope.new(*args).deliver
end

# Plan to configure with an adapter and allow for async delivers

# def deliver_async(email_name, attributes)
# end
#
# def deliver_in(interval, email_name, attributes)
# end

end
end
2 changes: 1 addition & 1 deletion lib/courrier/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Courrier
VERSION = "0.1.0"
VERSION = "1.0.1"
end

0 comments on commit c74217e

Please sign in to comment.