Module: CapGun::Helper

Public Instance Methods


convert_from_utc (timestamp)

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.

    # File lib/cap_gun.rb, line 64
64:     def convert_from_utc(timestamp)
65:       # we know Capistrano release timestaps are UTC, but Ruby doesn't, so make it explicit
66:       utc_time = timestamp << "UTC" 
67:       datetime = DateTime.parse(utc_time)
68:       datetime.new_offset(local_datetime_zone_offset)
69:     end

current_user ()

Current user - unsupported on Windows, patches welcome

    # File lib/cap_gun.rb, line 43
43:     def current_user
44:       platform.include?('mswin') ? nil : `id -un`.strip
45:     end

humanize_release_time (path)

Gives you a prettier date/time for output form the standard Capistrano timestamp‘ed release directory. This assumes Capistrano uses UTC for its date/timestamped directories, and converts to the local machine timezone.

    # File lib/cap_gun.rb, line 55
55:     def humanize_release_time(path)
56:       match = path.match(/(\d+)$/)
57:       return unless match
58:       local = convert_from_utc(match[1])
59:       local.strftime("%B #{local.day.ordinalize}, %Y %l:%M %p #{local_timezone}").gsub(/\s+/, ' ').strip
60:     end

load_mailer_config (cap)

Loads ActionMailer settings from a Capistrano variable called "cap_gun_action_mailer_config"

    # File lib/cap_gun.rb, line 35
35:     def load_mailer_config(cap) 
36:       raise ArgumentError, "You must define ActionMailer settings in 'cap_gun_action_mailer_config'" unless cap.cap_gun_action_mailer_config 
37:       raise ArgumentError, "Need at least one recipient." if !cap.exists?(:cap_gun_email_envelope) || cap[:cap_gun_email_envelope][:recipients].blank?
38:       
39:       ActionMailer::Base.smtp_settings = cap.cap_gun_action_mailer_config
40:     end

local_datetime_zone_offset ()

    # File lib/cap_gun.rb, line 71
71:     def local_datetime_zone_offset
72:       @local_datetime_zone_offset ||= DateTime.now.offset
73:     end

local_timezone ()

    # File lib/cap_gun.rb, line 75
75:     def local_timezone
76:       @current_timezone ||= Time.now.zone
77:     end

platform ()

stub hook purposes only

    # File lib/cap_gun.rb, line 48
48:     def platform
49:       RUBY_PLATFORM
50:     end