1class PetitionMailer < ApplicationMailer
 
2  include ActiveSupport::NumberHelper
 
3
  • Complexity 1 » saikuro
4  def email_confirmation_for_signer(signature)
 
5    @signature, @petition = signature, signature.petition
 
6    mail to: @signature.email, subject: subject_for(:email_confirmation_for_signer)
 
7  end
 
8
  • Complexity 1 » saikuro
 9  def email_duplicate_signatures(signature)
 
10    @signature, @petition = signature, signature.petition
 
11    mail to: @signature.email, subject: subject_for(:email_duplicate_signatures)
 
12  end
 
  • Complexity 1 » saikuro
14  def email_signer(petition, signature, email)
 
15    @petition, @signature, @email = petition, signature, email
 
 
17    mail to: @signature.email,
 
18      subject: subject_for(:email_signer),
 
19      list_unsubscribe: unsubscribe_url
 
20  end
 
  • Complexity 1 » saikuro
22  def email_creator(petition, signature, email)
 
23    @petition, @signature, @email = petition, signature, email
 
24    mail to: @signature.email,
 
25      subject: subject_for(:email_creator),
 
26      list_unsubscribe: unsubscribe_url
 
27  end
 
  • Complexity 1 » saikuro
29  def special_resend_of_email_confirmation_for_signer(signature)
 
30    @signature, @petition = signature, signature.petition
 
31    mail to: @signature.email, subject: subject_for(:special_resend_of_email_confirmation_for_signer)
 
32  end
 
  • Complexity 1 » saikuro
34  def notify_creator_that_petition_is_published(signature)
 
35    @signature, @petition = signature, signature.petition
 
 
37    mail to: @signature.email,
 
38      subject: subject_for(:notify_creator_that_petition_is_published),
 
39      list_unsubscribe: unsubscribe_url
 
40  end
 
  • Complexity 1 » saikuro
42  def notify_sponsor_that_petition_is_published(signature)
 
43    @signature, @petition = signature, signature.petition
 
44    mail to: @signature.email, subject: subject_for(:notify_sponsor_that_petition_is_published)
 
45  end
 
  • DuplicateMethodCall - calls 'signature.petition' 2 times » reek
  • Complexity 1 » saikuro
47  def notify_creator_that_petition_was_rejected(signature)
 
48    @signature, @petition, @rejection = signature, signature.petition, signature.petition.rejection
 
49    mail to: @signature.email, subject: subject_for(:notify_creator_that_petition_was_rejected)
 
50  end
 
  • DuplicateMethodCall - calls 'signature.petition' 2 times » reek
  • Complexity 1 » saikuro
52  def notify_sponsor_that_petition_was_rejected(signature)
 
53    @signature, @petition, @rejection = signature, signature.petition, signature.petition.rejection
 
54    mail to: @signature.email, subject: subject_for(:notify_sponsor_that_petition_was_rejected)
 
55  end
 
  • Complexity 1 » saikuro
57  def notify_signer_of_threshold_response(petition, signature)
 
58    @petition, @signature, @government_response = petition, signature, petition.government_response
 
 
60    mail to: @signature.email,
 
61      subject: subject_for(:notify_signer_of_threshold_response),
 
62      list_unsubscribe: unsubscribe_url
 
63  end
 
  • Complexity 1 » saikuro
65  def notify_creator_of_threshold_response(petition, signature)
 
66    @petition, @signature, @government_response = petition, signature, petition.government_response
 
 
68    mail to: @signature.email,
 
69      subject: subject_for(:notify_creator_of_threshold_response),
 
70      list_unsubscribe: unsubscribe_url
 
71  end
 
  • Complexity 1 » saikuro
73  def notify_creator_of_closing_date_change(signature, dissolution_at = Parliament.dissolution_at)
 
74    @signature, @petition = signature, signature.petition
 
 
76    @closing_time = dissolution_at.strftime('%H:%M%P')
 
77    @closing_date = dissolution_at.strftime('%-d %B')
 
78    @last_response_date = dissolution_at.yesterday.strftime('%-d %B')
 
 
80    mail to: @signature.email, subject: subject_for(:notify_creator_of_closing_date_change)
 
81  end
 
  • Complexity 1 » saikuro
83  def notify_creator_of_sponsored_petition_being_stopped(signature)
 
84    @signature, @petition = signature, signature.petition
 
85    mail to: @signature.email, subject: subject_for(:notify_creator_of_sponsored_petition_being_stopped)
 
86  end
 
  • Complexity 1 » saikuro
88  def notify_creator_of_validated_petition_being_stopped(signature)
 
89    @signature, @petition = signature, signature.petition
 
90    mail to: @signature.email, subject: subject_for(:notify_creator_of_validated_petition_being_stopped)
 
91  end
 
  • Complexity 1 » saikuro
93  def gather_sponsors_for_petition(petition, bcc = nil)
 
94    @petition, @creator = petition, petition.creator
 
95    mail to: @creator.email, bcc: bcc, subject: subject_for(:gather_sponsors_for_petition)
 
96  end
 
  • Complexity 2 » saikuro
98  def notify_signer_of_debate_outcome(petition, signature)
 
 99    @petition, @debate_outcome, @signature = petition, petition.debate_outcome, signature
 
 
101    if @debate_outcome.debated?
 
102      subject = subject_for(:notify_signer_of_positive_debate_outcome)
 
103    else
 
104      subject = subject_for(:notify_signer_of_negative_debate_outcome)
 
105    end
 
 
107    mail to: @signature.email, subject: subject, list_unsubscribe: unsubscribe_url
 
108  end
 
  • Complexity 2 » saikuro
110  def notify_creator_of_debate_outcome(petition, signature)
 
111    @petition, @debate_outcome, @signature = petition, petition.debate_outcome, signature
 
 
113    if @debate_outcome.debated?
 
114      subject = subject_for(:notify_creator_of_positive_debate_outcome)
 
115    else
 
116      subject = subject_for(:notify_creator_of_negative_debate_outcome)
 
117    end
 
 
119    mail to: @signature.email, subject: subject, list_unsubscribe: unsubscribe_url
 
120  end
 
  • Complexity 1 » saikuro
122  def notify_signer_of_debate_scheduled(petition, signature)
 
123    @petition, @signature = petition, signature
 
 
125    mail to: @signature.email,
 
126      subject: subject_for(:notify_signer_of_debate_scheduled),
 
127      list_unsubscribe: unsubscribe_url
 
128  end
 
  • Complexity 1 » saikuro
130  def notify_creator_of_debate_scheduled(petition, signature)
 
131    @petition, @signature = petition, signature
 
132    mail to: @signature.email,
 
133      subject: subject_for(:notify_creator_of_debate_scheduled),
 
134      list_unsubscribe: unsubscribe_url
 
135  end
 
  • Complexity 1 » saikuro
137  def notify_creator_that_moderation_is_delayed(signature, subject, body)
 
138    @petition, @signature = signature.petition, signature
 
139    @subject, @body = subject, body
 
 
141    mail to: @signature.email,
 
142      subject: subject_for(:notify_creator_that_moderation_is_delayed),
 
143      list_unsubscribe: unsubscribe_url
 
144  end
 
 
146  private
 
  • Complexity 1 » saikuro
148  def subject_for(key, options = {})
 
149    I18n.t key, i18n_options.merge(options)
 
150  end
 
  • Complexity 1 » saikuro
152  def signature_belongs_to_creator?
 
153    @signature && @signature.creator?
 
154  end
 
  • DuplicateMethodCall - calls '@petition.signature_count' 2 times » reek
  • TooManyStatements - has approx 7 statements » reek
  • Complexity 5 » saikuro
156  def i18n_options
 
157    {}.tap do |options|
 
158      options[:scope] = :"petitions.emails.subjects"
 
 
160      if defined?(@petition)
 
161        options[:count] = @petition.signature_count
 
162        options[:formatted_count] = number_to_delimited(@petition.signature_count)
 
163        options[:action] = @petition.action
 
164      end
 
 
166      if defined?(@email)
 
167        options[:subject] = @email.subject
 
168      end
 
 
170      if defined?(@subject)
 
171        options[:subject] = @subject
 
172      end
 
173    end
 
174  end
 
  • Complexity 1 » saikuro
176  def unsubscribe_url
 
177    "<#{unsubscribe_signature_url(@signature, token: @signature.unsubscribe_token)}>"
 
178  end
 
179end