2008-12-01 15:19:55 -05:00
task :rails_env do
2010-01-12 08:11:47 -05:00
# TODO Do we really need this?
2008-12-01 15:19:55 -05:00
unless defined? RAILS_ENV
RAILS_ENV = ENV [ 'RAILS_ENV' ] || = 'development'
end
end
2010-09-07 05:41:34 -04:00
desc 'Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions).'
2007-12-16 18:10:48 -05:00
task :secret do
2011-05-23 14:45:49 -04:00
require 'securerandom'
2011-05-23 07:02:06 -04:00
puts SecureRandom . hex ( 64 )
2007-12-14 21:27:56 -05:00
end
2008-03-21 21:59:09 -04:00
2010-06-09 17:14:47 -04:00
desc 'List versions of all Rails frameworks and the environment'
2011-07-31 12:09:10 -04:00
task :about = > :environment do
2010-02-02 19:03:47 -05:00
puts Rails :: Info
end
2008-03-21 21:59:09 -04:00
namespace :time do
namespace :zones do
2010-06-09 16:19:03 -04:00
desc 'Displays all time zones, also available: time:zones:us, time:zones:local -- filter with OFFSET parameter, e.g., OFFSET=-6'
2008-03-27 21:45:04 -04:00
task :all do
2008-03-21 21:59:09 -04:00
build_time_zone_list ( :all )
end
2010-03-20 13:34:21 -04:00
2010-06-09 16:19:03 -04:00
# desc 'Displays names of US time zones recognized by the Rails TimeZone class, grouped by offset. Results can be filtered with optional OFFSET parameter, e.g., OFFSET=-6'
2008-03-27 21:45:04 -04:00
task :us do
2008-03-21 21:59:09 -04:00
build_time_zone_list ( :us_zones )
end
2010-03-20 13:34:21 -04:00
2010-06-09 16:19:03 -04:00
# desc 'Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time'
2008-03-27 21:45:04 -04:00
task :local do
2009-04-28 20:58:51 -04:00
require 'active_support'
2009-05-20 20:11:41 -04:00
require 'active_support/time'
2008-04-12 17:06:29 -04:00
jan_offset = Time . now . beginning_of_year . utc_offset
jul_offset = Time . now . beginning_of_year . change ( :month = > 7 ) . utc_offset
offset = jan_offset < jul_offset ? jan_offset : jul_offset
build_time_zone_list ( :all , offset )
2008-03-21 21:59:09 -04:00
end
2010-03-20 13:34:21 -04:00
2008-03-21 21:59:09 -04:00
# to find UTC -06:00 zones, OFFSET can be set to either -6, -6:00 or 21600
def build_time_zone_list ( method , offset = ENV [ 'OFFSET' ] )
2009-04-28 20:58:51 -04:00
require 'active_support'
2009-05-20 20:11:41 -04:00
require 'active_support/time'
2008-03-21 21:59:09 -04:00
if offset
offset = if offset . to_s . match ( / ( \ +|-)?( \ d+):( \ d+) / )
sign = $1 == '-' ? - 1 : 1
hours , minutes = $2 . to_f , $3 . to_f
( ( hours * 3600 ) + ( minutes . to_f * 60 ) ) * sign
elsif offset . to_f . abs < = 13
offset . to_f * 3600
else
offset . to_f
end
end
previous_offset = nil
2008-07-04 15:07:00 -04:00
ActiveSupport :: TimeZone . __send__ ( method ) . each do | zone |
2008-03-21 21:59:09 -04:00
if offset . nil? || offset == zone . utc_offset
puts " \n * UTC #{ zone . formatted_offset } * " unless zone . utc_offset == previous_offset
puts zone . name
previous_offset = zone . utc_offset
end
end
puts " \n "
end
end
2008-08-27 06:42:08 -04:00
end