Module: Mailkick::Legacy
- Defined in:
- lib/mailkick/legacy.rb
Class Method Summary collapse
- .opt_in(options) ⇒ Object
- .opt_out(options) ⇒ Object
- .opt_outs(options = {}) ⇒ Object
-
.opt_outs? ⇒ Boolean
checks for table as long as it exists.
- .opted_out?(options) ⇒ Boolean
- .opted_out_emails(options = {}) ⇒ Object
- .opted_out_users(options = {}) ⇒ Object
Class Method Details
.opt_in(options) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/mailkick/legacy.rb', line 30 def self.opt_in() opt_outs().each do |opt_out| opt_out.active = false opt_out.save! end true end |
.opt_out(options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mailkick/legacy.rb', line 15 def self.opt_out() unless opted_out?() time = [:time] || Time.now Mailkick::OptOut.create! do |o| o.email = [:email] o.user = [:user] o.reason = [:reason] || "unsubscribe" o.list = [:list] o.created_at = time o.updated_at = time end end true end |
.opt_outs(options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mailkick/legacy.rb', line 38 def self.opt_outs( = {}) relation = Mailkick::OptOut.where(active: true) contact_relation = Mailkick::OptOut.none if (email = [:email]) contact_relation = contact_relation.or(Mailkick::OptOut.where(email: email)) end if (user = [:user]) contact_relation = contact_relation.or( Mailkick::OptOut.where("user_id = ? AND user_type = ?", user.id, user.class.name) ) end relation = relation.merge(contact_relation) if email || user relation = if [:list] relation.where("list IS NULL OR list = ?", [:list]) else relation.where("list IS NULL") end relation end |
.opt_outs? ⇒ Boolean
checks for table as long as it exists
4 5 6 7 8 9 |
# File 'lib/mailkick/legacy.rb', line 4 def self.opt_outs? unless defined?(@opt_outs) && @opt_outs == false @opt_outs = ActiveRecord::Base.connection.table_exists?("mailkick_opt_outs") end @opt_outs end |
.opted_out?(options) ⇒ Boolean
11 12 13 |
# File 'lib/mailkick/legacy.rb', line 11 def self.opted_out?() opt_outs().any? end |
.opted_out_emails(options = {}) ⇒ Object
62 63 64 |
# File 'lib/mailkick/legacy.rb', line 62 def self.opted_out_emails( = {}) Set.new(opt_outs().where.not(email: nil).distinct.pluck(:email)) end |
.opted_out_users(options = {}) ⇒ Object
66 67 68 |
# File 'lib/mailkick/legacy.rb', line 66 def self.opted_out_users( = {}) Set.new(opt_outs().where.not(user_id: nil).map(&:user)) end |