Class: NotifyUser::Unsubscribe

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/notify_user/unsubscribe.rb

Class Method Summary collapse

Class Method Details

.for_target(target) ⇒ Object



18
19
20
21
# File 'app/models/notify_user/unsubscribe.rb', line 18

def self.for_target(target)
  where(target_id: target.id)
  .where(target_type: target.class.base_class)
end

.has_unsubscribed_from(target, type) ⇒ Object



38
39
40
41
42
# File 'app/models/notify_user/unsubscribe.rb', line 38

def self.has_unsubscribed_from(target, type)
  where(target_id: target.id)
  .where(target_type: target.class.base_class)
  .where(type: type)
end

.toggle_status(target, type) ⇒ Object



23
24
25
26
27
28
29
# File 'app/models/notify_user/unsubscribe.rb', line 23

def self.toggle_status(target, type)
  if NotifyUser::Unsubscribe.has_unsubscribed_from(target, type).empty?
    NotifyUser::Unsubscribe.create(target: target, type: type)
  else
    NotifyUser::Unsubscribe.unsubscribe(target,type)
  end 
end

.unsubscribe(target, type) ⇒ Object



31
32
33
34
35
36
# File 'app/models/notify_user/unsubscribe.rb', line 31

def self.unsubscribe(target, type)
  #deletes unsubscribe object in essence subscribing a user
  where(target_id: target.id)
  .where(target_type: target.class.base_class)
  .where(type: type).destroy_all
end