diff --git a/lib/courrier.rb b/lib/courrier.rb index 68136c9..69a9d84 100644 --- a/lib/courrier.rb +++ b/lib/courrier.rb @@ -2,6 +2,7 @@ require "courrier/envelope" require "courrier/email" require "courrier/configuration" +require "courrier/notifier" module Courrier class << self diff --git a/lib/courrier/configuration.rb b/lib/courrier/configuration.rb index 805b607..fe69fb0 100644 --- a/lib/courrier/configuration.rb +++ b/lib/courrier/configuration.rb @@ -1,5 +1,6 @@ module Courrier class Configuration attr_accessor :mailer + attr_accessor :interceptor_email end end diff --git a/lib/courrier/email.rb b/lib/courrier/email.rb index b9b888e..68e74f4 100644 --- a/lib/courrier/email.rb +++ b/lib/courrier/email.rb @@ -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) diff --git a/lib/courrier/envelope.rb b/lib/courrier/envelope.rb index b1a896d..0e50404 100644 --- a/lib/courrier/envelope.rb +++ b/lib/courrier/envelope.rb @@ -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) @@ -35,8 +34,7 @@ def mailer end def recipient_email - case recipient - when User + if emailable?(recipient) recipient.email else recipient @@ -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 diff --git a/lib/courrier/notifier.rb b/lib/courrier/notifier.rb new file mode 100644 index 0000000..e42e788 --- /dev/null +++ b/lib/courrier/notifier.rb @@ -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 diff --git a/lib/courrier/version.rb b/lib/courrier/version.rb index 7bb37bd..bc90c00 100644 --- a/lib/courrier/version.rb +++ b/lib/courrier/version.rb @@ -1,3 +1,3 @@ module Courrier - VERSION = "0.1.0" + VERSION = "1.0.1" end