-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
122 lines (93 loc) · 2.48 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
desc "Creates a default user"
task :create_user do
db = load_sequel
$LOAD_PATH.unshift File.dirname(__FILE__) + "/models/"
require 'user'
require 'blog'
user = User.new
print "name: "
user.name = STDIN.gets.chomp
print "openid: "
user.openid = STDIN.gets.chomp
print "email: "
user.email = STDIN.gets.chomp
user.blog = Blog.default
if user.save
puts "User created."
else
puts "User not created."
end
end
desc "Creates a default blog"
task :create_blog do
db = load_sequel
$LOAD_PATH.unshift File.dirname(__FILE__) + "/models/"
require 'blog'
print "Do you want to clear out previously created blogs?"
print "If not, the last created blog will be the default. [N]: "
answer = STDIN.gets.chomp
if answer.downcase == "y"
puts "Blogs clearing..."
Blog.delete
puts "Blogs cleared!"
end
blog = Blog.new
print "domain: "
blog.domain = STDIN.gets.chomp
print "title: "
blog.title = STDIN.gets.chomp
print "tagline: "
blog.tagline = STDIN.gets.chomp
print "permalink [/:year/:month/:day/:title]: "
blog.permalink = STDIN.gets.chomp
print "theme [default]: "
blog.theme = STDIN.gets.chomp
print "external rss feed: "
blog.external_rss_feed = STDIN.gets.chomp
if blog.save
puts "Blog created."
else
puts "Blog not created."
end
end
namespace :db do
desc "Creates the default database"
task :init do
# Ensure that sqlite3 file is there
unless File.exist?('db/blog.db')
require 'sqlite3'
db = SQLite3::Database.new('db/blog.db')
db.close
end
db = load_sequel
Sequel::Migrator.apply(db, 'db/migrations')
end
desc "[WARNING] Clears the database. Drops all tables and data."
task :clear do
db = load_sequel
print "Are you sure you want to clear? [N]: "
answer = STDIN.gets.chomp
if answer.downcase == "y"
puts "Database clearing..."
Sequel::Migrator.apply(db, 'db/migrations', 0, nil)
puts "Database cleared!"
else
puts "Database not cleared!"
end
end
desc "Updates the database"
task :update do
db = load_sequel
Sequel::Migrator.apply(db, 'db/migrations')
end
end
require 'spec/rake/spectask'
Spec::Rake::SpecTask.new do |t|
t.spec_files = FileList['spec/**/*.rb']
end
def load_sequel
$LOAD_PATH.unshift File.dirname(__FILE__) + "/vendor/sequel/lib"
require 'sequel'
require 'sequel/extensions/migration'
Sequel.sqlite('db/blog.db')
end