public
Rubygem
Description: Bang! You've deployed!
Homepage: http://opensource.thinkrelevance.com/
Clone URL: git://github.com/relevance/cap_gun.git
Search Repo:
time zone support and some better docs
rsanheim (author)
Sat Apr 19 19:31:37 -0700 2008
commit  9df8aecefeece13a3b2549e896102e6477845520
tree    92c94fbc12a472ad962efc45c18d0f9416691ade
parent  aa6b3524fcf8fabd3916a3ac33f9311691910d8e
...
 
 
1
...
1
2
3
0
@@ -1 +1,3 @@
0
+v0.0.2. Converts the release times to the current time zone; improved docs.
0
+
0
 v0.0.1. Initial release. Rock n roll mcdonalds.
...
26
27
28
29
 
30
31
32
...
38
39
40
41
 
42
43
44
...
48
49
50
51
52
53
 
 
 
54
55
56
57
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
60
61
...
70
71
72
 
 
 
 
 
73
74
75
...
26
27
28
 
29
30
31
32
...
38
39
40
 
41
42
43
44
...
48
49
50
 
 
 
51
52
53
54
55
56
 
 
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
...
87
88
89
90
91
92
93
94
95
96
97
0
@@ -26,7 +26,7 @@ require File.join(File.dirname(__FILE__), *%w[.. vendor action_mailer_tls lib sm
0
 # cap -s comment="fix for bug #303" deploy
0
 #
0
 module CapGun
0
- VERSION = '0.0.1'
0
+ VERSION = '0.0.2'
0
 
0
   module Helper
0
     
0
@@ -38,7 +38,7 @@ module CapGun
0
       ActionMailer::Base.smtp_settings = cap.cap_gun_action_mailer_config
0
     end
0
   
0
- # Current user - unsupported on Windows
0
+ # Current user - unsupported on Windows, patches welcome
0
     def current_user
0
       platform.include?('mswin') ? nil : `id -un`.strip
0
     end
0
@@ -48,14 +48,31 @@ module CapGun
0
       RUBY_PLATFORM
0
     end
0
   
0
- # Assuming the standard Capistrano timestamp directory, gives you a prettier date/time for output.
0
- # This does not take into account anything to do with timezones, but I believe Capistrano always
0
- # uses UTC so we could convert to a specified time zone for even friendlier display.
0
+ # Gives you a prettier date/time for output form the standard Capistrano timestamp'ed release directory.
0
+ # This assumes Capistrano uses UTC for its date/timestamped directories, and converts to the local
0
+ # machine timezone.
0
     def humanize_release_time(path)
0
       match = path.match(/(\d+)$/)
0
       return unless match
0
- time = Time.parse(match[1])
0
- time.strftime("%B #{time.day.ordinalize}, %Y %l:%M %p %Z").gsub(/\s+/, ' ').strip
0
+ local = convert_from_utc(match[1])
0
+ local.strftime("%B #{local.day.ordinalize}, %Y %l:%M %p #{local_timezone}").gsub(/\s+/, ' ').strip
0
+ end
0
+
0
+ # Use some DateTime magicrey to convert UTC to the current time zone
0
+ # When the whole world is on Rails 2.1 (and therefore new ActiveSupport) we can use the magic timezone support there.
0
+ def convert_from_utc(timestamp)
0
+ # we know Capistrano release timestaps are UTC, but Ruby doesn't, so make it explicit
0
+ utc_time = timestamp << "UTC"
0
+ datetime = DateTime.parse(utc_time)
0
+ datetime.new_offset(local_datetime_zone_offset)
0
+ end
0
+
0
+ def local_datetime_zone_offset
0
+ @local_datetime_zone_offset ||= DateTime.now.offset
0
+ end
0
+
0
+ def local_timezone
0
+ @current_timezone ||= Time.now.zone
0
     end
0
     
0
     extend self
0
@@ -70,6 +87,11 @@ module CapGun
0
       adv_attr_accessor :email_prefix
0
       
0
       # Grab the options for emaililng from cap_gun_email_envelope (should be set in your deploy file)
0
+ #
0
+ # Valid options:
0
+ # :recipients (required) an array or string of email address(es) who should get notifications
0
+ # :from the sender of the notification, defaults to cap_gun@example.com
0
+ # :email_prefix subject prefix, defaults to [DEPLOY]
0
       def init(envelope = {})
0
         recipients envelope[:recipients]
0
         from (envelope[:from] || DEFAULT_SENDER)
...
56
57
58
 
 
 
 
 
 
 
 
 
 
59
60
61
62
63
64
 
 
 
 
 
65
66
67
...
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
 
74
75
76
77
78
79
80
81
0
@@ -56,12 +56,26 @@ describe "CapGun" do
0
       current_user
0
     end
0
     
0
+ end
0
+
0
+ describe "handling release time" do
0
+ include CapGun::Helper
0
+
0
+ before do # make DateTime act as if local timezone is EDT
0
+ stubs(:local_timezone).returns("EDT")
0
+ stubs(:local_datetime_zone_offset).returns(Rational(-1,6))
0
+ end
0
+
0
     it "returns nil for weird release path" do
0
       humanize_release_time("/data/foo/my_release").should == nil
0
     end
0
     
0
     it "parse datetime from release path" do
0
- humanize_release_time("/data/foo/releases/20080402152141").should == "April 2nd, 2008 3:21 PM EDT"
0
+ humanize_release_time("/data/foo/releases/20080227120000").should == "February 27th, 2008 8:00 AM EDT"
0
+ end
0
+
0
+ it "converts time from release into localtime" do
0
+ humanize_release_time("/data/foo/releases/20080410040000").should == "April 10th, 2008 12:00 AM EDT"
0
     end
0
     
0
   end

Comments

    No one has commented yet.