Class: Receipt
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Receipt
- Defined in:
- app/models/receipt.rb
Class Method Summary collapse
-
.mark_as_read(options = {}) ⇒ Object
Marks all the receipts from the relation as read.
-
.mark_as_unread(options = {}) ⇒ Object
Marks all the receipts from the relation as unread.
-
.move_to_inbox(options = {}) ⇒ Object
Moves all the receipts from the relation to inbox.
-
.move_to_sentbox(options = {}) ⇒ Object
Moves all the receipts from the relation to sentbox.
-
.move_to_trash(options = {}) ⇒ Object
Marks all the receipts from the relation as trashed.
-
.untrash(options = {}) ⇒ Object
Marks all the receipts from the relation as not trashed.
-
.update_receipts(updates, options = {}) ⇒ Object
This methods helps to do a update_all with table joins, not currently supported by rails.
Instance Method Summary collapse
-
#conversation ⇒ Object
Returns the conversation associated to the receipt if the notification is a Message.
-
#is_trashed? ⇒ Boolean
Returns if the participant have trashed the Notification.
-
#is_unread? ⇒ Boolean
Returns if the participant have read the Notification.
-
#mark_as_read ⇒ Object
Marks the receipt as read.
-
#mark_as_unread ⇒ Object
Marks the receipt as unread.
-
#move_to_inbox ⇒ Object
Moves the receipt to inbox.
-
#move_to_sentbox ⇒ Object
Moves the receipt to sentbox.
-
#move_to_trash ⇒ Object
Marks the receipt as trashed.
-
#untrash ⇒ Object
Marks the receipt as not trashed.
Class Method Details
.mark_as_read(options = {}) ⇒ Object
Marks all the receipts from the relation as read
31 32 33 |
# File 'app/models/receipt.rb', line 31 def mark_as_read(={}) update_receipts({:is_read => true}, ) end |
.mark_as_unread(options = {}) ⇒ Object
Marks all the receipts from the relation as unread
36 37 38 |
# File 'app/models/receipt.rb', line 36 def mark_as_unread(={}) update_receipts({:is_read => false}, ) end |
.move_to_inbox(options = {}) ⇒ Object
Moves all the receipts from the relation to inbox
51 52 53 |
# File 'app/models/receipt.rb', line 51 def move_to_inbox(={}) update_receipts({:mailbox_type => :inbox, :trashed => false}, ) end |
.move_to_sentbox(options = {}) ⇒ Object
Moves all the receipts from the relation to sentbox
56 57 58 |
# File 'app/models/receipt.rb', line 56 def move_to_sentbox(={}) update_receipts({:mailbox_type => :sentbox, :trashed => false}, ) end |
.move_to_trash(options = {}) ⇒ Object
Marks all the receipts from the relation as trashed
41 42 43 |
# File 'app/models/receipt.rb', line 41 def move_to_trash(={}) update_receipts({:trashed => true}, ) end |
.untrash(options = {}) ⇒ Object
Marks all the receipts from the relation as not trashed
46 47 48 |
# File 'app/models/receipt.rb', line 46 def untrash(={}) update_receipts({:trashed => false}, ) end |
.update_receipts(updates, options = {}) ⇒ Object
This methods helps to do a update_all with table joins, not currently supported by rails. Acording to the github ticket github.com/rails/rails/issues/522 it should be supported with 3.2.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/models/receipt.rb', line 63 def update_receipts(updates,={}) ids = Array.new where().each do |rcp| ids << rcp.id end return if ids.empty? conditions = [""].concat(ids) condition = "id = ? " ids.drop(1).each do condition << "OR id = ? " end conditions[0] = condition Receipt.except(:where).except(:joins).where(conditions).update_all(updates) end |
Instance Method Details
#conversation ⇒ Object
Returns the conversation associated to the receipt if the notification is a Message
110 111 112 113 |
# File 'app/models/receipt.rb', line 110 def conversation return .conversation if .is_a? Message return nil end |
#is_trashed? ⇒ Boolean
Returns if the participant have trashed the Notification
121 122 123 |
# File 'app/models/receipt.rb', line 121 def is_trashed? return self.trashed end |
#is_unread? ⇒ Boolean
Returns if the participant have read the Notification
116 117 118 |
# File 'app/models/receipt.rb', line 116 def is_unread? return !self.is_read end |
#mark_as_read ⇒ Object
Marks the receipt as read
80 81 82 |
# File 'app/models/receipt.rb', line 80 def mark_as_read update_attributes(:is_read => true) end |
#mark_as_unread ⇒ Object
Marks the receipt as unread
85 86 87 |
# File 'app/models/receipt.rb', line 85 def mark_as_unread update_attributes(:is_read => false) end |
#move_to_inbox ⇒ Object
Moves the receipt to inbox
100 101 102 |
# File 'app/models/receipt.rb', line 100 def move_to_inbox update_attributes(:mailbox_type => :inbox, :trashed => false) end |
#move_to_sentbox ⇒ Object
Moves the receipt to sentbox
105 106 107 |
# File 'app/models/receipt.rb', line 105 def move_to_sentbox update_attributes(:mailbox_type => :sentbox, :trashed => false) end |
#move_to_trash ⇒ Object
Marks the receipt as trashed
90 91 92 |
# File 'app/models/receipt.rb', line 90 def move_to_trash update_attributes(:trashed => true) end |
#untrash ⇒ Object
Marks the receipt as not trashed
95 96 97 |
# File 'app/models/receipt.rb', line 95 def untrash update_attributes(:trashed => false) end |