Module: Capistrano::Notifier::Helpers::Mail

Defined in:
lib/capistrano/notifier/helpers/mail.rb

Instance Method Summary collapse

Instance Method Details

#applicationObject



5
6
7
# File 'lib/capistrano/notifier/helpers/mail.rb', line 5

def application
  fetch :application
end

#branchObject



9
10
11
# File 'lib/capistrano/notifier/helpers/mail.rb', line 9

def branch
  fetch(:branch, "master")
end

#content_type_for_format(format = nil) ⇒ Object



125
126
127
# File 'lib/capistrano/notifier/helpers/mail.rb', line 125

def content_type_for_format(format = nil)
  format == :html ? 'text/html' : 'text/plain'
end

#delivery_methodObject



90
91
92
# File 'lib/capistrano/notifier/helpers/mail.rb', line 90

def delivery_method
  notifier_mail_options[:method]
end

#email_formatObject



58
59
60
# File 'lib/capistrano/notifier/helpers/mail.rb', line 58

def email_format
  notifier_mail_options[:format] || :text
end

#email_fromObject



66
67
68
# File 'lib/capistrano/notifier/helpers/mail.rb', line 66

def email_from
  notifier_mail_options[:from]
end

#email_subjectObject



98
99
100
101
# File 'lib/capistrano/notifier/helpers/mail.rb', line 98

def email_subject
  notifier_mail_options[:subject] ||
    "#{application} branch #{branch} deployed to #{stage}"
end

#email_templateObject



62
63
64
# File 'lib/capistrano/notifier/helpers/mail.rb', line 62

def email_template
  notifier_mail_options[:template] || "mail.#{email_format.to_s}.erb"
end

#email_textObject



117
118
119
# File 'lib/capistrano/notifier/helpers/mail.rb', line 117

def email_text
  render_template(email_template)
end

#email_toObject



121
122
123
# File 'lib/capistrano/notifier/helpers/mail.rb', line 121

def email_to
  notifier_mail_options[:to]
end

#git_commit_prefixObject



82
83
84
# File 'lib/capistrano/notifier/helpers/mail.rb', line 82

def git_commit_prefix
  "#{git_prefix}/commit"
end

#git_compare_prefixObject



86
87
88
# File 'lib/capistrano/notifier/helpers/mail.rb', line 86

def git_compare_prefix
  "#{git_prefix}/compare"
end

#git_current_revisionObject



13
14
15
# File 'lib/capistrano/notifier/helpers/mail.rb', line 13

def git_current_revision
  fetch :current_revision
end

#git_logObject



34
35
36
37
38
39
40
# File 'lib/capistrano/notifier/helpers/mail.rb', line 34

def git_log
  return unless git_range
  command =
    git_log_command || 'git log #{git_range} --no-merges --format=format:"%h %s (%an)"'

  system_call(command)
end

#git_log_commandObject



30
31
32
# File 'lib/capistrano/notifier/helpers/mail.rb', line 30

def git_log_command
  notifier_mail_options[:log_command]
end

#git_prefixObject



78
79
80
# File 'lib/capistrano/notifier/helpers/mail.rb', line 78

def git_prefix
  giturl ? giturl : "https://github.com/#{github}"
end

#git_previous_revisionObject



17
18
19
# File 'lib/capistrano/notifier/helpers/mail.rb', line 17

def git_previous_revision
  fetch :previous_revision
end

#git_range(ranger = "..") ⇒ Object



21
22
23
24
# File 'lib/capistrano/notifier/helpers/mail.rb', line 21

def git_range(ranger = "..")
  return unless git_previous_revision && git_current_revision
  "#{git_previous_revision}#{ranger}#{git_current_revision}"
end

#githubObject



70
71
72
# File 'lib/capistrano/notifier/helpers/mail.rb', line 70

def github
  notifier_mail_options[:github]
end

#github_rangeObject



26
27
28
# File 'lib/capistrano/notifier/helpers/mail.rb', line 26

def github_range
  git_range("...")
end

#giturlObject



74
75
76
# File 'lib/capistrano/notifier/helpers/mail.rb', line 74

def giturl
  notifier_mail_options[:giturl]
end

#notifier_mail_optionsObject



54
55
56
# File 'lib/capistrano/notifier/helpers/mail.rb', line 54

def notifier_mail_options
  @notifier_mail_options ||= fetch :notifier_mail_options
end

#notifier_smtp_settingsObject



94
95
96
# File 'lib/capistrano/notifier/helpers/mail.rb', line 94

def notifier_smtp_settings
  notifier_mail_options[:smtp_settings]
end

#nowObject



42
43
44
# File 'lib/capistrano/notifier/helpers/mail.rb', line 42

def now
  @now ||= Time.now
end

#render_template(template_name) ⇒ Object



103
104
105
106
107
108
109
110
111
# File 'lib/capistrano/notifier/helpers/mail.rb', line 103

def render_template(template_name)
  config_file = "#{templates_path}/#{template_name}"

  unless File.exists?(config_file)
    config_file = File.join(File.dirname(__FILE__),'..', "templates/#{template_name}")
  end

  ERB.new(File.read(config_file), nil, '-').result(binding)
end

#stageObject



46
47
48
# File 'lib/capistrano/notifier/helpers/mail.rb', line 46

def stage
  fetch :stage
end

#system_call(command) ⇒ Object



129
130
131
# File 'lib/capistrano/notifier/helpers/mail.rb', line 129

def system_call(command)
  `#{command}`
end

#templates_pathObject



113
114
115
# File 'lib/capistrano/notifier/helpers/mail.rb', line 113

def templates_path
  notifier_mail_options[:templates_path] || 'config/deploy/templates'
end

#user_nameObject



50
51
52
# File 'lib/capistrano/notifier/helpers/mail.rb', line 50

def user_name
  ENV['DEPLOYER'] || system_call("git config --get user.name").strip
end