1module Archived
 
2  class PetitionMailer < ApplicationMailer
 
3    include ActiveSupport::NumberHelper
 
4
  • Complexity 1 » saikuro
5    def email_signer(petition, signature, email)
 
6      @petition, @signature, @email = petition, signature, email
 
7
 
8      mail to: @signature.email,
 
 9        subject: subject_for(:email_signer),
 
10        list_unsubscribe: unsubscribe_url
 
11    end
 
  • Complexity 1 » saikuro
13    def email_creator(petition, signature, email)
 
14      @petition, @signature, @email = petition, signature, email
 
15      mail to: @signature.email,
 
16        subject: subject_for(:email_creator),
 
17        list_unsubscribe: unsubscribe_url
 
18    end
 
  • Complexity 1 » saikuro
20    def notify_signer_of_threshold_response(petition, signature)
 
21      @petition, @signature = petition, signature
 
22      @government_response, @parliament = petition.government_response, petition.parliament
 
 
24      mail to: @signature.email,
 
25        subject: subject_for(:notify_signer_of_threshold_response),
 
26        list_unsubscribe: unsubscribe_url
 
27    end
 
  • Complexity 1 » saikuro
29    def notify_creator_of_threshold_response(petition, signature)
 
30      @petition, @signature = petition, signature
 
31      @government_response, @parliament = petition.government_response, petition.parliament
 
 
33      mail to: @signature.email,
 
34        subject: subject_for(:notify_creator_of_threshold_response),
 
35        list_unsubscribe: unsubscribe_url
 
36    end
 
  • Complexity 1 » saikuro
38    def notify_signer_of_debate_scheduled(petition, signature)
 
39      @petition, @signature = petition, signature
 
 
41      mail to: @signature.email,
 
42        subject: subject_for(:notify_signer_of_debate_scheduled),
 
43        list_unsubscribe: unsubscribe_url
 
44    end
 
  • Complexity 1 » saikuro
46    def notify_creator_of_debate_scheduled(petition, signature)
 
47      @petition, @signature = petition, signature
 
48      mail to: @signature.email,
 
49        subject: subject_for(:notify_creator_of_debate_scheduled),
 
50        list_unsubscribe: unsubscribe_url
 
51    end
 
  • Complexity 2 » saikuro
53    def notify_signer_of_debate_outcome(petition, signature)
 
54      @petition, @debate_outcome, @signature = petition, petition.debate_outcome, signature
 
 
56      if @debate_outcome.debated?
 
57        subject = subject_for(:notify_signer_of_positive_debate_outcome)
 
58      else
 
59        subject = subject_for(:notify_signer_of_negative_debate_outcome)
 
60      end
 
 
62      mail to: @signature.email, subject: subject, list_unsubscribe: unsubscribe_url
 
63    end
 
  • Complexity 2 » saikuro
65    def notify_creator_of_debate_outcome(petition, signature)
 
66      @petition, @debate_outcome, @signature = petition, petition.debate_outcome, signature
 
 
68      if @debate_outcome.debated?
 
69        subject = subject_for(:notify_creator_of_positive_debate_outcome)
 
70      else
 
71        subject = subject_for(:notify_creator_of_negative_debate_outcome)
 
72      end
 
 
74      mail to: @signature.email, subject: subject, list_unsubscribe: unsubscribe_url
 
75    end
 
 
77    private
 
  • Complexity 1 » saikuro
79    def subject_for(key, options = {})
 
80      I18n.t key, i18n_options.merge(options)
 
81    end
 
  • Complexity 1 » saikuro
83    def signature_belongs_to_creator?
 
84      @signature && @signature.creator?
 
85    end
 
  • DuplicateMethodCall - calls '@petition.signature_count' 2 times » reek
  • TooManyStatements - has approx 6 statements » reek
  • Complexity 4 » saikuro
87    def i18n_options
 
88      {}.tap do |options|
 
89        options[:scope] = :"petitions.emails.subjects"
 
 
91        if defined?(@petition)
 
92          options[:count] = @petition.signature_count
 
93          options[:formatted_count] = number_to_delimited(@petition.signature_count)
 
94          options[:action] = @petition.action
 
95        end
 
 
97        if defined?(@email)
 
98          options[:subject] = @email.subject
 
 99        end
 
100      end
 
101    end
 
  • Complexity 1 » saikuro
103    def unsubscribe_url
 
104      "<#{unsubscribe_archived_signature_url(@signature, token: @signature.unsubscribe_token)}>"
 
105    end
 
106  end
 
107end