lib/cap_gun.rb in cap_gun-0.0.2 vs lib/cap_gun.rb in cap_gun-0.0.5

- old
+ new

@@ -25,11 +25,11 @@ # # cap -s comment="fix for bug #303" deploy # # See README for full install/config instructions. module CapGun - VERSION = '0.0.2' + VERSION = '0.0.5' module Helper # Loads ActionMailer settings from a Capistrano variable called "cap_gun_action_mailer_config" def load_mailer_config(cap) @@ -51,10 +51,11 @@ # 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. 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 @@ -81,15 +82,16 @@ # This mailer is configured with a capistrano variable called "cap_gun_email_envelope" class Mailer < ActionMailer::Base include CapGun::Helper DEFAULT_SENDER = %("CapGun" <cap_gun@example.com>) - DEFAULT_EMAIL_PREFIX = "[DEPLOY] " + DEFAULT_EMAIL_PREFIX = "[DEPLOY]" adv_attr_accessor :email_prefix + attr_accessor :summary - # Grab the options for emaililng from cap_gun_email_envelope (should be set in your deploy file) + # Grab the options for emailing from cap_gun_email_envelope (should be set in your deploy file) # # Valid options: # :recipients (required) an array or string of email address(es) that should get notifications # :from the sender of the notification, defaults to cap_gun@example.com # :email_prefix subject prefix, defaults to [DEPLOY] @@ -100,19 +102,28 @@ end # Do the actual email def deployment_notification(capistrano) init(capistrano[:cap_gun_email_envelope]) + self.summary = create_summary(capistrano) content_type "text/plain" - subject "#{email_prefix} #{capistrano[:application]} deployed to #{capistrano[:rails_env]}" + subject "#{email_prefix} #{capistrano[:application]} #{deployed_to(capistrano)}" body create_body(capistrano) end + def create_summary(capistrano) + %[#{capistrano[:application]} was deployed#{" to " << capistrano[:rails_env] if capistrano[:rails_env]} by #{current_user} at #{humanize_release_time(capistrano[:current_release])}.] + end + + def deployed_to(capistrano) + returning(s = "deployed") { s += " to #{capistrano[:rails_env]}" if capistrano[:rails_env] } + end + # Create the body of the message using a bunch of values from Capistrano def create_body(capistrano) <<-EOL -#{capistrano[:application]} was deployed to #{capistrano[:rails_env]} by #{current_user} at #{humanize_release_time(capistrano[:current_release])}. +#{summary} Comment: #{capistrano[:comment] || "[none given]"} Nerd details ============ \ No newline at end of file