Class: NotifyUser::Unsubscribe
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- NotifyUser::Unsubscribe
- Defined in:
- app/models/notify_user/unsubscribe.rb
Class Method Summary collapse
- .for_target(target) ⇒ Object
- .has_unsubscribed_from(target, type) ⇒ Object
- .toggle_status(target, type) ⇒ Object
- .unsubscribe(target, type) ⇒ Object
Class Method Details
.for_target(target) ⇒ Object
20 21 22 23 |
# File 'app/models/notify_user/unsubscribe.rb', line 20 def self.for_target(target) where(target_id: target.id) .where(target_type: target.class.base_class) end |
.has_unsubscribed_from(target, type) ⇒ Object
40 41 42 43 44 |
# File 'app/models/notify_user/unsubscribe.rb', line 40 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
25 26 27 28 29 30 31 |
# File 'app/models/notify_user/unsubscribe.rb', line 25 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
33 34 35 36 37 38 |
# File 'app/models/notify_user/unsubscribe.rb', line 33 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 |