Class: CapGun::Presenter
- Inherits:
-
Object
- Object
- CapGun::Presenter
- Defined in:
- lib/cap_gun/presenter.rb
Constant Summary collapse
- DEFAULT_SENDER =
%("CapGun" <[email protected]>)
- DEFAULT_EMAIL_PREFIX =
"[DEPLOY]"
Instance Attribute Summary collapse
-
#capistrano ⇒ Object
Returns the value of attribute capistrano.
Instance Method Summary collapse
- #body ⇒ Object
- #branch ⇒ Object
- #comment ⇒ Object
-
#convert_from_utc(timestamp) ⇒ Object
Use some DateTime magicrey to convert UTC to the current time zone When the whole world is on Rails 2.1 (and therefore new ActiveSupport) we can use the magic timezone support there.
- #current_user ⇒ Object
- #deployed_to ⇒ Object
- #email_prefix ⇒ Object
- #exit_code ⇒ Object
- #from ⇒ Object
-
#humanize_release_time(path) ⇒ Object
Gives you a prettier date/time for output from the standard Capistrano timestamped release directory.
-
#initialize(capistrano) ⇒ Presenter
constructor
A new instance of Presenter.
- #local_datetime_zone_offset ⇒ Object
- #local_timezone ⇒ Object
- #previous_release_time ⇒ Object
- #previous_revision ⇒ Object
- #recipients ⇒ Object
- #release_time ⇒ Object
- #repository ⇒ Object
- #scm_details ⇒ Object
- #scm_log ⇒ Object
- #scm_log_messages ⇒ Object
- #subject ⇒ Object
- #summary ⇒ Object
Constructor Details
#initialize(capistrano) ⇒ Presenter
Returns a new instance of Presenter.
10 11 12 |
# File 'lib/cap_gun/presenter.rb', line 10 def initialize(capistrano) self.capistrano = capistrano end |
Instance Attribute Details
#capistrano ⇒ Object
Returns the value of attribute capistrano.
8 9 10 |
# File 'lib/cap_gun/presenter.rb', line 8 def capistrano @capistrano end |
Instance Method Details
#body ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/cap_gun/presenter.rb', line 125 def body body = "#{summary}\n" body << "#{comment}\n" body << "Deployment details\n" body << "====================\n" body << "Release: #{capistrano[:current_release]}\n" body << "Release Time: #{release_time}\n" body << "Release Revision: #{capistrano[:current_revision]}\n" body << "\n" body << "Previous Release: #{capistrano[:previous_release]}\n" body << "Previous Release Time: #{previous_release_time}\n" body << "Previous Release Revision: #{previous_revision}\n" body << "\n" body << "Repository: #{repository}\n" body << "Deploy path: #{capistrano[:deploy_to]}\n" body << "Domain: #{capistrano[:domain]}\n" if capistrano[:domain] body << "#{scm_details}\n" body end |
#branch ⇒ Object
39 40 41 |
# File 'lib/cap_gun/presenter.rb', line 39 def branch "Branch: #{capistrano[:branch]}" unless capistrano[:branch].nil? || capistrano[:branch].empty? end |
#comment ⇒ Object
117 118 119 |
# File 'lib/cap_gun/presenter.rb', line 117 def comment "Comment: #{capistrano[:comment]}.\n" if capistrano[:comment] end |
#convert_from_utc(timestamp) ⇒ Object
Use some DateTime magicrey to convert UTC to the current time zone When the whole world is on Rails 2.1 (and therefore new ActiveSupport) we can use the magic timezone support there.
86 87 88 89 90 91 |
# File 'lib/cap_gun/presenter.rb', line 86 def convert_from_utc() # we know Capistrano release timestamps are UTC, but Ruby doesn't, so make it explicit utc_time = << "UTC" datetime = DateTime.parse(utc_time) datetime.new_offset(local_datetime_zone_offset) end |
#current_user ⇒ Object
26 27 28 |
# File 'lib/cap_gun/presenter.rb', line 26 def current_user Etc.getlogin end |
#deployed_to ⇒ Object
34 35 36 37 |
# File 'lib/cap_gun/presenter.rb', line 34 def deployed_to return "deployed to #{capistrano[:rails_env]}" if capistrano[:rails_env] "deployed" end |
#email_prefix ⇒ Object
18 19 20 |
# File 'lib/cap_gun/presenter.rb', line 18 def email_prefix capistrano[:cap_gun_email_envelope][:email_prefix] || DEFAULT_EMAIL_PREFIX end |
#exit_code ⇒ Object
69 70 71 |
# File 'lib/cap_gun/presenter.rb', line 69 def exit_code $? end |
#from ⇒ Object
22 23 24 |
# File 'lib/cap_gun/presenter.rb', line 22 def from capistrano[:cap_gun_email_envelope][:from] || DEFAULT_SENDER end |
#humanize_release_time(path) ⇒ Object
Gives you a prettier date/time for output from the standard Capistrano timestamped release directory. This assumes Capistrano uses UTC for its date/timestamped directories, and converts to the local machine timezone.
76 77 78 79 80 81 82 |
# File 'lib/cap_gun/presenter.rb', line 76 def humanize_release_time(path) return unless path match = path.match(/(\d+)$/) return unless match local = convert_from_utc(match[1]) local.strftime("%B #{local.day.ordinalize}, %Y %l:%M %p #{local_timezone}").gsub(/\s+/, ' ').strip end |
#local_datetime_zone_offset ⇒ Object
93 94 95 |
# File 'lib/cap_gun/presenter.rb', line 93 def local_datetime_zone_offset @local_datetime_zone_offset ||= DateTime.now.offset end |
#local_timezone ⇒ Object
97 98 99 |
# File 'lib/cap_gun/presenter.rb', line 97 def local_timezone @current_timezone ||= Time.now.zone end |
#previous_release_time ⇒ Object
109 110 111 |
# File 'lib/cap_gun/presenter.rb', line 109 def previous_release_time humanize_release_time(capistrano[:previous_release]) end |
#previous_revision ⇒ Object
105 106 107 |
# File 'lib/cap_gun/presenter.rb', line 105 def previous_revision capistrano.fetch(:previous_revision, "n/a") end |
#recipients ⇒ Object
14 15 16 |
# File 'lib/cap_gun/presenter.rb', line 14 def recipients capistrano[:cap_gun_email_envelope][:recipients] end |
#release_time ⇒ Object
101 102 103 |
# File 'lib/cap_gun/presenter.rb', line 101 def release_time humanize_release_time(capistrano[:current_release]) end |
#repository ⇒ Object
121 122 123 |
# File 'lib/cap_gun/presenter.rb', line 121 def repository capistrano[:repository_url] || capistrano[:repository] end |
#scm_details ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/cap_gun/presenter.rb', line 43 def scm_details return unless [:git,:subversion].include? capistrano[:scm].to_sym <<-EOL #{branch} #{scm_log} EOL rescue nil end |
#scm_log ⇒ Object
53 54 55 |
# File 'lib/cap_gun/presenter.rb', line 53 def scm_log "\nCommits since last release\n====================\n#{}" end |
#scm_log_messages ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cap_gun/presenter.rb', line 57 def = case capistrano[:scm].to_sym when :git `git log #{previous_revision}..#{capistrano[:current_revision]} --pretty=format:%h:%s` when :subversion `svn log -r #{previous_revision.to_i+1}:#{capistrano[:current_revision]}` else "N/A" end exit_code.success? ? : "N/A" end |
#subject ⇒ Object
113 114 115 |
# File 'lib/cap_gun/presenter.rb', line 113 def subject "#{email_prefix} #{capistrano[:application]} #{deployed_to}" end |
#summary ⇒ Object
30 31 32 |
# File 'lib/cap_gun/presenter.rb', line 30 def summary %[#{capistrano[:application]} was #{deployed_to} by #{current_user} at #{release_time}.] end |