Skip to content

Commit c74217e

Browse files
Merge pull request #1 from challengepost/remove-settings
configurable interceptor email and remove Settings depedency
2 parents 55ce950 + 0bb02cf commit c74217e

File tree

6 files changed

+28
-6
lines changed

6 files changed

+28
-6
lines changed

lib/courrier.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require "courrier/envelope"
33
require "courrier/email"
44
require "courrier/configuration"
5+
require "courrier/notifier"
56

67
module Courrier
78
class << self

lib/courrier/configuration.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Courrier
22
class Configuration
33
attr_accessor :mailer
4+
attr_accessor :interceptor_email
45
end
56
end

lib/courrier/email.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def self.subclass_by_email_name(email_name)
7070
end
7171

7272
def recipient
73-
return Settings.interceptor_emails.first if Settings.interceptor_emails.any?
73+
return Courrier.configuration.interceptor_email if Courrier.configuration.interceptor_email.present?
7474
method = self.class.recipient_method
7575
raise Courrier::RecipientUndefinedError.new("Please declare a recipient in #{self.class.name}") if method.nil? || !self.respond_to?(method, true)
7676
send(method)

lib/courrier/envelope.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ def deliver
1212
log "Delivering #{email_name} to #{recipient_email}"
1313
payload.tap do |args|
1414

15-
case recipient
16-
when User
15+
if emailable?(recipient)
1716
Courrier.configuration.mailer.transactional_email_to_user(*args)
1817
else
1918
Courrier.configuration.mailer.transactional_email_to_address(*args)
@@ -35,8 +34,7 @@ def mailer
3534
end
3635

3736
def recipient_email
38-
case recipient
39-
when User
37+
if emailable?(recipient)
4038
recipient.email
4139
else
4240
recipient
@@ -51,5 +49,9 @@ def log(info)
5149
Rails.logger.info "#{self.class.name} -- #{info}"
5250
end
5351

52+
def emailable?(recipient)
53+
recipient.respond_to? :email
54+
end
55+
5456
end
5557
end

lib/courrier/notifier.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Courrier
2+
module Notifier
3+
extend self
4+
5+
def deliver(*args)
6+
Courrier::Envelope.new(*args).deliver
7+
end
8+
9+
# Plan to configure with an adapter and allow for async delivers
10+
11+
# def deliver_async(email_name, attributes)
12+
# end
13+
#
14+
# def deliver_in(interval, email_name, attributes)
15+
# end
16+
17+
end
18+
end

lib/courrier/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Courrier
2-
VERSION = "0.1.0"
2+
VERSION = "1.0.1"
33
end

0 commit comments

Comments
 (0)