Class: Notification

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/generators/notifykit/templates/app/models/notification.rb

Instance Method Summary collapse

Instance Method Details

#cancelObject



34
35
36
37
# File 'lib/generators/notifykit/templates/app/models/notification.rb', line 34

def cancel
  return true if self.cancelled_at.present?
  self.update_attribute(:cancelled_at, Time.now)
end

#cancelled?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/generators/notifykit/templates/app/models/notification.rb', line 39

def cancelled?
  self.cancelled_at.present?
end

#clickObject



14
15
16
17
18
19
# File 'lib/generators/notifykit/templates/app/models/notification.rb', line 14

def click
  return false if self.cancelled?
  self.click_count += 1
  self.clicked_at ||= Time.now
  self.save
end

#deliverObject



48
49
50
51
52
# File 'lib/generators/notifykit/templates/app/models/notification.rb', line 48

def deliver
  return if self.email_sent_at.present? || !self.deliver_via_email?

  NotificationsMailer.notify(self.id).deliver
end

#ignoreObject



28
29
30
31
32
# File 'lib/generators/notifykit/templates/app/models/notification.rb', line 28

def ignore
  return false if self.cancelled?
  self.ignored_at ||= Time.now
  self.save
end

#readObject



21
22
23
24
25
26
# File 'lib/generators/notifykit/templates/app/models/notification.rb', line 21

def read
  return false if self.cancelled?
  self.read_count += 1
  self.read_at ||= Time.now
  self.save
end

#to_paramObject



54
55
56
# File 'lib/generators/notifykit/templates/app/models/notification.rb', line 54

def to_param
  self.token
end

#unsubscribeObject



43
44
45
46
# File 'lib/generators/notifykit/templates/app/models/notification.rb', line 43

def unsubscribe
  self.unsubscribed_at ||= Time.now
  self.save
end