GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Mail   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 92
ccs 46
cts 46
cp 1
rs 10
wmc 14

10 Methods

Rating   Name   Duplication   Size   Complexity  
A from_template() 0 4 1
A deliver() 0 11 1
A r.notify() 0 3 1
A subject_template() 0 4 1
A apply_template() 0 13 1
A body_template() 0 4 1
A to_template() 0 4 1
A get_template_interpolation() 0 12 4
A get_rails_variable() 0 8 3
A apply_template_modifiers() 0 14 1
1 1
module Textris
2 1
  module Delivery
3 1
    class Mail < Textris::Delivery::Base
4 1
      class Mailer < ActionMailer::Base
5 1
        def notify(from, to, subject, body)
6 1
          mail :from => from, :to => to, :subject => subject, :body => body
7
        end
8
      end
9
10 1
      def deliver(to)
11 12
        template_vars = { :to_phone => to }
12
13 12
        from    = apply_template from_template,    template_vars
14 12
        to      = apply_template to_template,      template_vars
15 12
        subject = apply_template subject_template, template_vars
16 12
        body    = apply_template body_template,    template_vars
17
18
        ::Textris::Delivery::Mail::Mailer.notify(
19 12
          from, to, subject, body).deliver
20
      end
21
22 1
      private
23
24 1
      def from_template
25
        Rails.application.config.try(:textris_mail_from_template) ||
26 12
          "%{from_name:d}-%{from_phone}@%{env:d}.%{app:d}.com"
27
      end
28
29 1
      def to_template
30
        Rails.application.config.try(:textris_mail_to_template) ||
31 12
          "%{app:d}-%{env:d}-%{to_phone}[email protected]"
32
      end
33
34 1
      def subject_template
35
        Rails.application.config.try(:textris_mail_subject_template) ||
36 12
          "%{texter:dh} texter: %{action:h}"
37
      end
38
39 1
      def body_template
40
        Rails.application.config.try(:textris_mail_body_template) ||
41 12
          "%{content}"
42
      end
43
44 1
      def apply_template(template, variables)
45 48
        template.gsub(/\%\{[a-z_:]+\}/) do |match|
46 124
          directive = match.gsub(/[%{}]/, '')
47 124
          key       = directive.split(':').first
48 124
          modifiers = directive.split(':')[1] || ''
49
50 124
          content = get_template_interpolation(key, variables)
51 124
          content = apply_template_modifiers(content, modifiers.chars)
52 124
          content = 'unknown' unless content.present?
53
54 124
          content
55
        end
56
      end
57
58 1
      def get_template_interpolation(key, variables)
59
        case key
60
        when 'app', 'env'
61 38
          get_rails_variable(key)
62
        when 'texter', 'action', 'from_name', 'from_phone', 'content'
63 76
          message.send(key)
64
        when 'media_urls'
65 2
          message.media_urls.join(', ')
66
        else
67 8
          variables[key.to_sym]
68 124
        end.to_s.strip
69
      end
70
71 1
      def get_rails_variable(var)
72 38
        case var
73
        when 'app'
74 20
          Rails.application.class.parent_name
75
        when 'env'
76 18
          Rails.env
77
        end
78
      end
79
80 1
      def apply_template_modifiers(content, modifiers)
81 124
        modifiers.each do |modifier|
82 80
          case modifier
83
          when 'd'
84 52
            content = content.underscore.dasherize
85
          when 'h'
86 24
            content = content.humanize.gsub(/[-_]/, ' ')
87
          when 'p'
88 2
            content = Phony.format(content) rescue content
89
          end
90
        end
91
92 124
        content
93
      end
94
    end
95
  end
96
end
97