1class Petition < ActiveRecord::Base |
|
2 class Statistics < ActiveRecord::Base |
|
3 belongs_to :petition |
|
5 after_commit on: :create do |
|
6 UpdatePetitionStatisticsJob.perform_later(petition) |
|
7 end |
|
9 def refresh!(now = Time.current) |
|
10 update!(
|
|
11 refreshed_at: now, |
|
12 duplicate_emails: refresh_duplicate_emails, |
|
13 pending_rate: refresh_pending_rate |
|
14 )
|
|
15 end |
|
17 def refreshed? |
|
18 refreshed_at?
|
|
19 end |
|
21 private
|
|
23 def refresh_duplicate_emails |
|
24 petition.signatures.duplicate_emails
|
|
25 end |
|
27 def refresh_pending_rate |
|
28 petition.signatures.pending_rate
|
|
29 end |
|
30 end |
|
31end |