From 0ac394656df38bb80ad424687bb751d9a3e232a1 Mon Sep 17 00:00:00 2001 From: devpost-mzheng Date: Mon, 7 Jan 2019 17:10:34 -0500 Subject: [PATCH 1/9] configurable interceptor email and remove Settings depedency --- lib/courrier/configuration.rb | 1 + lib/courrier/email.rb | 2 +- lib/courrier/version.rb | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) 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..3528f30 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.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/version.rb b/lib/courrier/version.rb index 7bb37bd..59df6e8 100644 --- a/lib/courrier/version.rb +++ b/lib/courrier/version.rb @@ -1,3 +1,3 @@ module Courrier - VERSION = "0.1.0" + VERSION = "0.1.1" end From 23a6becbeba0e9bf0bec805229244d7234d88172 Mon Sep 17 00:00:00 2001 From: devpost-mzheng Date: Mon, 7 Jan 2019 17:29:58 -0500 Subject: [PATCH 2/9] allow for projects without user --- lib/courrier/envelope.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/courrier/envelope.rb b/lib/courrier/envelope.rb index b1a896d..b2faac1 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 Object.const_defined? 'User' and recipient.kind_of?(User) Courrier.configuration.mailer.transactional_email_to_user(*args) else Courrier.configuration.mailer.transactional_email_to_address(*args) From 5c8e747802ecc09f10586d5d9faab2670fe38fe8 Mon Sep 17 00:00:00 2001 From: devpost-mzheng Date: Mon, 7 Jan 2019 17:35:17 -0500 Subject: [PATCH 3/9] function for user check --- lib/courrier/envelope.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/courrier/envelope.rb b/lib/courrier/envelope.rb index b2faac1..1be3dfb 100644 --- a/lib/courrier/envelope.rb +++ b/lib/courrier/envelope.rb @@ -12,7 +12,7 @@ def deliver log "Delivering #{email_name} to #{recipient_email}" payload.tap do |args| - if Object.const_defined? 'User' and recipient.kind_of?(User) + if is_user?(recipient) Courrier.configuration.mailer.transactional_email_to_user(*args) else Courrier.configuration.mailer.transactional_email_to_address(*args) @@ -34,8 +34,7 @@ def mailer end def recipient_email - case recipient - when User + if is_user?(recipient) recipient.email else recipient @@ -50,5 +49,9 @@ def log(info) Rails.logger.info "#{self.class.name} -- #{info}" end + def is_user?(recipient) + Object.const_defined? 'User' and recipient.kind_of?(User) + end + end end From af1219ca4ff9e07813da84e833bc4f8a531beea4 Mon Sep 17 00:00:00 2001 From: devpost-mzheng Date: Tue, 8 Jan 2019 12:08:50 -0500 Subject: [PATCH 4/9] match with tagging --- lib/courrier/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/courrier/version.rb b/lib/courrier/version.rb index 59df6e8..bc90c00 100644 --- a/lib/courrier/version.rb +++ b/lib/courrier/version.rb @@ -1,3 +1,3 @@ module Courrier - VERSION = "0.1.1" + VERSION = "1.0.1" end From df1dc41c878ce520dc0664a727be8e43d2b672ea Mon Sep 17 00:00:00 2001 From: devpost-mzheng Date: Tue, 8 Jan 2019 12:35:05 -0500 Subject: [PATCH 5/9] fix logic --- lib/courrier/email.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/courrier/email.rb b/lib/courrier/email.rb index 3528f30..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 Courrier.configuration.interceptor_email if Courrier.configuration.present? + 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) From d1a070c91c9373378f48835b871be38a657e41ca Mon Sep 17 00:00:00 2001 From: devpost-mzheng Date: Wed, 9 Jan 2019 16:31:35 -0500 Subject: [PATCH 6/9] CR refactor --- lib/courrier/envelope.rb | 6 +++--- lib/courrier/notifier.rb | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 lib/courrier/notifier.rb diff --git a/lib/courrier/envelope.rb b/lib/courrier/envelope.rb index 1be3dfb..16049ce 100644 --- a/lib/courrier/envelope.rb +++ b/lib/courrier/envelope.rb @@ -34,7 +34,7 @@ def mailer end def recipient_email - if is_user?(recipient) + if emailable?(recipient) recipient.email else recipient @@ -49,8 +49,8 @@ def log(info) Rails.logger.info "#{self.class.name} -- #{info}" end - def is_user?(recipient) - Object.const_defined? 'User' and recipient.kind_of?(User) + def emailable?(recipient) + recipient.respond_to? :email 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 From 2e4168befde2ecc9fcb00a8ea56bf235108d4c0a Mon Sep 17 00:00:00 2001 From: devpost-mzheng Date: Wed, 9 Jan 2019 16:55:57 -0500 Subject: [PATCH 7/9] require --- lib/courrier.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/courrier.rb b/lib/courrier.rb index 68136c9..9e73c8e 100644 --- a/lib/courrier.rb +++ b/lib/courrier.rb @@ -1,7 +1,4 @@ -require "courrier/version" -require "courrier/envelope" -require "courrier/email" -require "courrier/configuration" +Dir.glob(File.join('courrier', '**', '*.rb'), &method(:require)) module Courrier class << self From b02350056e8218499c59e16360cf2a498097df05 Mon Sep 17 00:00:00 2001 From: devpost-mzheng Date: Wed, 9 Jan 2019 17:15:25 -0500 Subject: [PATCH 8/9] fix require --- lib/courrier.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/courrier.rb b/lib/courrier.rb index 9e73c8e..69a9d84 100644 --- a/lib/courrier.rb +++ b/lib/courrier.rb @@ -1,4 +1,8 @@ -Dir.glob(File.join('courrier', '**', '*.rb'), &method(:require)) +require "courrier/version" +require "courrier/envelope" +require "courrier/email" +require "courrier/configuration" +require "courrier/notifier" module Courrier class << self From 0bb02cfee0336902b1615c6760bc0cbc27dcad55 Mon Sep 17 00:00:00 2001 From: devpost-mzheng Date: Wed, 9 Jan 2019 17:28:52 -0500 Subject: [PATCH 9/9] fix a condition --- lib/courrier/envelope.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/courrier/envelope.rb b/lib/courrier/envelope.rb index 16049ce..0e50404 100644 --- a/lib/courrier/envelope.rb +++ b/lib/courrier/envelope.rb @@ -12,7 +12,7 @@ def deliver log "Delivering #{email_name} to #{recipient_email}" payload.tap do |args| - if is_user?(recipient) + if emailable?(recipient) Courrier.configuration.mailer.transactional_email_to_user(*args) else Courrier.configuration.mailer.transactional_email_to_address(*args)