Class: Alerter::Receipt

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/alerter/receipt.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.mark_as_deleted(options = {}) ⇒ Object

Marks the receipt as deleted



43
44
45
# File 'app/models/alerter/receipt.rb', line 43

def mark_as_deleted(options={})
  update_receipts({:deleted => true}, options)
end

.mark_as_not_deleted(options = {}) ⇒ Object

Marks the receipt as not deleted



48
49
50
# File 'app/models/alerter/receipt.rb', line 48

def mark_as_not_deleted(options={})
  update_receipts({:deleted => false}, options)
end

.mark_as_read(options = {}) ⇒ Object

Marks all the receipts from the relation as read



33
34
35
# File 'app/models/alerter/receipt.rb', line 33

def mark_as_read(options={})
  update_receipts({:is_read => true}, options)
end

.mark_as_unread(options = {}) ⇒ Object

Marks all the receipts from the relation as unread



38
39
40
# File 'app/models/alerter/receipt.rb', line 38

def mark_as_unread(options={})
  update_receipts({:is_read => false}, options)
end

.update_receipts(updates, options = {}) ⇒ Object



53
54
55
56
57
58
59
60
# File 'app/models/alerter/receipt.rb', line 53

def update_receipts(updates, options={})
  ids = where(options).map { |rcp| rcp.id }
  unless ids.empty?
    sql = ids.map { "#{table_name}.id = ? " }.join(' OR ')
    conditions = [sql].concat(ids)
    Alerter::Receipt.where(conditions).update_all(updates)
  end
end

Instance Method Details

#is_unread?Boolean

Returns if the participant has read the Notification

Returns:

  • (Boolean)


85
86
87
# File 'app/models/alerter/receipt.rb', line 85

def is_unread?
  !is_read
end

#mark_as_deletedObject

Marks the receipt as deleted



65
66
67
# File 'app/models/alerter/receipt.rb', line 65

def mark_as_deleted
  update_attributes(:deleted => true)
end

#mark_as_not_deletedObject

Marks the receipt as not deleted



70
71
72
# File 'app/models/alerter/receipt.rb', line 70

def mark_as_not_deleted
  update_attributes(:deleted => false)
end

#mark_as_readObject

Marks the receipt as read



75
76
77
# File 'app/models/alerter/receipt.rb', line 75

def mark_as_read
  update_attributes(:is_read => true)
end

#mark_as_unreadObject

Marks the receipt as unread



80
81
82
# File 'app/models/alerter/receipt.rb', line 80

def mark_as_unread
  update_attributes(:is_read => false)
end