-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathRakefile
98 lines (85 loc) · 2.76 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
$: << File.join(File.dirname(__FILE__), 'lib')
require 'rubygems'
require 'rake/gempackagetask'
# If this require failes, try "gem install rspec"
require 'spec/rake/spectask'
require 'time'
file_list = FileList['spec/*_spec.rb']
Spec::Rake::SpecTask.new('spec') do |t|
t.spec_files = file_list
end
desc 'Default: run specs.'
task :default => 'spec'
desc "cron task for keeping the CAN updated. Run once every hour."
task :cron => 'seinfeld:init' do
if Time.now.hour % 4 == 0
Seinfeld::User.paginated_each do |user|
user.update_progress
end
end
end
namespace :seinfeld do
task :init do
$: << File.join(File.dirname(__FILE__), 'lib')
require 'seinfeld/models'
require 'seinfeld/calendar_helper'
require File.dirname(__FILE__) + '/config/seinfeld.rb'
end
desc "Initial setup."
task :setup => :init do
DataMapper.auto_migrate!
puts "Database reset"
end
desc "Inspect USER."
task :show => :init do
raise "Need USER=" if ENV['USER'].to_s.size.zero?
u = Seinfeld::User.first(:login => ENV['USER'])
puts "#{u.login}#{" #{u.time_zone}" if u.time_zone}"
puts "Current Streak: #{u.current_streak} #{u.streak_start} => #{u.streak_end}"
puts "Longest Streak: #{u.longest_streak} #{u.longest_streak_start} => #{u.longest_streak_end}"
end
desc "Sets USER's timezone to ZONE."
task :tz => :init do
raise "Need USER=" if ENV['USER'].to_s.size.zero?
raise "Need ZONE=" if ENV['ZONE'].to_s.size.zero?
zone = ActiveSupport::TimeZone::MAPPING[ENV['ZONE']] || ActiveSupport::TimeZone::MAPPING.index(ENV['ZONE']) || raise("Bad Time Zone")
u = Seinfeld::User.first(:login => ENV['USER'])
u.time_zone = zone
u.save
end
desc "Add a USER to the database."
task :add => :init do
raise "Need USER=" if ENV['USER'].to_s.size.zero?
Seinfeld::User.create(:login => ENV['USER'])
end
desc "Remove a USER from the database."
task :drop => :init do
raise "Need USER=" if ENV['USER'].to_s.size.zero?
Seinfeld::User.first(:login => ENV['USER']).destroy
end
desc "Update the calendar of USER"
task :update => :init do
if ENV['USER'].to_s.size.zero?
Seinfeld::User.paginated_each do |user|
user.update_progress
end
else
user = Seinfeld::User.first(:login => ENV['USER'])
if user
user.update_progress
else
raise "No user found for #{ENV['USER'].inspect}"
end
end
end
desc "Clear progress of USER."
task :clear => :init do
raise "Need USER=" if ENV['USER'].to_s.size.zero?
Seinfeld::User.first(:login => ENV['USER']).clear_progress
end
desc "Resets progress of USER."
task :reset => :init do
raise "Need USER=" if ENV['USER'].to_s.size.zero?
Seinfeld::User.first(:login => ENV['USER']).reset_progress
end
end