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
- #git_details ⇒ Object
- #git_log ⇒ Object
- #git_log_messages ⇒ 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
- #present_time(time) ⇒ Object
- #previous_release_time ⇒ Object
- #recipients ⇒ Object
- #release_time ⇒ 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
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/cap_gun/presenter.rb', line 115 def body <<-EOL #{summary} #{comment} Deployment details ================== Current Branch: #{capistrano[:current_revision]} Release Revision: #{capistrano[:latest_revision]} Previous Release Revision: #{capistrano[:previous_revision]} Repository: #{capistrano[:repository]} Deploy path: #{capistrano[:deploy_to]} Domain: #{capistrano[:domain]} #{git_details} EOL end |
#branch ⇒ Object
40 41 42 |
# File 'lib/cap_gun/presenter.rb', line 40 def branch "Branch: #{capistrano[:branch]}" unless capistrano[:branch].nil? || capistrano[:branch].empty? end |
#comment ⇒ Object
111 112 113 |
# File 'lib/cap_gun/presenter.rb', line 111 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.
84 85 86 87 88 89 |
# File 'lib/cap_gun/presenter.rb', line 84 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
27 28 29 |
# File 'lib/cap_gun/presenter.rb', line 27 def current_user Etc.getlogin end |
#deployed_to ⇒ Object
35 36 37 38 |
# File 'lib/cap_gun/presenter.rb', line 35 def deployed_to return "deployed to #{capistrano[:rails_env]}" if capistrano[:rails_env] "deployed" end |
#email_prefix ⇒ Object
19 20 21 |
# File 'lib/cap_gun/presenter.rb', line 19 def email_prefix capistrano[:cap_gun_email_envelope][:email_prefix] || DEFAULT_EMAIL_PREFIX end |
#exit_code ⇒ Object
63 64 65 |
# File 'lib/cap_gun/presenter.rb', line 63 def exit_code $? end |
#from ⇒ Object
23 24 25 |
# File 'lib/cap_gun/presenter.rb', line 23 def from capistrano[:cap_gun_email_envelope][:from] || DEFAULT_SENDER end |
#git_details ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/cap_gun/presenter.rb', line 44 def git_details return unless capistrano[:scm].to_sym == :git <<-EOL #{branch} #{git_log} EOL rescue nil end |
#git_log ⇒ Object
54 55 56 |
# File 'lib/cap_gun/presenter.rb', line 54 def git_log "\nCommits since last release\n====================\n#{}" end |
#git_log_messages ⇒ Object
58 59 60 61 |
# File 'lib/cap_gun/presenter.rb', line 58 def = `git log #{capistrano[:previous_revision]}..#{capistrano[:latest_revision]} --pretty=format:%h:%s` exit_code.success? ? : "N/A" 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.
70 71 72 73 74 75 76 |
# File 'lib/cap_gun/presenter.rb', line 70 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
91 92 93 |
# File 'lib/cap_gun/presenter.rb', line 91 def local_datetime_zone_offset @local_datetime_zone_offset ||= DateTime.now.offset end |
#local_timezone ⇒ Object
95 96 97 |
# File 'lib/cap_gun/presenter.rb', line 95 def local_timezone @current_timezone ||= Time.now.zone end |
#present_time(time) ⇒ Object
78 79 80 |
# File 'lib/cap_gun/presenter.rb', line 78 def present_time(time) time.strftime("%B #{time.day.ordinalize}, %Y %l:%M %p #{local_timezone}").gsub(/\s+/, ' ').strip end |
#previous_release_time ⇒ Object
103 104 105 |
# File 'lib/cap_gun/presenter.rb', line 103 def previous_release_time humanize_release_time(capistrano[:previous_release]) end |
#recipients ⇒ Object
15 16 17 |
# File 'lib/cap_gun/presenter.rb', line 15 def recipients capistrano[:cap_gun_email_envelope][:recipients] end |
#release_time ⇒ Object
99 100 101 |
# File 'lib/cap_gun/presenter.rb', line 99 def release_time present_time(Time.now) end |
#subject ⇒ Object
107 108 109 |
# File 'lib/cap_gun/presenter.rb', line 107 def subject "#{email_prefix} #{capistrano[:application]} #{deployed_to}" end |
#summary ⇒ Object
31 32 33 |
# File 'lib/cap_gun/presenter.rb', line 31 def summary %[#{capistrano[:application]} was #{deployed_to} by #{current_user} at #{release_time}.] end |