-
Notifications
You must be signed in to change notification settings - Fork 0
/
Thorfile
105 lines (85 loc) · 2.71 KB
/
Thorfile
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
class Monk < Thor
include Thor::Actions
desc "test [dir]", "Run all tests in the specified directory"
def test(dir = "**")
verify_config(:test)
$:.unshift File.join(File.dirname(__FILE__), "test")
Dir["test/#{dir}/*_test.rb"].each do |file|
load file unless file =~ /^-/
end
end
desc "stories", "Run user stories."
method_option :pdf, :type => :boolean
def stories
$:.unshift(Dir.pwd, "test")
ARGV << "-r"
ARGV << (options[:pdf] ? "stories-pdf" : "stories")
ARGV.delete("--pdf")
Dir["test/stories/*_test.rb"].each do |file|
load file
end
end
desc "start ENV", "Start Monk in the supplied environment"
def start(env = ENV["RACK_ENV"] || "development")
verify_config(env)
invoke :redis
exec "env RACK_ENV=#{env} ruby init.rb"
end
desc "copy_example EXAMPLE, TARGET", "Copies an example file to its destination"
def copy_example(example, target = target_file_for(example))
File.exists?(target) ? return : say_status(:missing, target)
File.exists?(example) ? copy_file(example, target) : say_status(:missing, example)
end
REDIS_ENV = ENV["RACK_ENV"] || "development"
REDIS_CNF = File.expand_path(File.join("config", "redis", "#{REDIS_ENV}.conf"), File.dirname(__FILE__))
REDIS_PID = File.expand_path(File.join("db", "redis", REDIS_ENV, "redis.pid"), File.dirname(__FILE__))
desc "redis START|STOP", "Start the Redis server"
def redis(action = "start")
case action
when "start" then redis_start
when "stop" then redis_stop
else say_status(:error, "Usage: monk redis start|stop")
end
end
desc "console", "Launch Monk console"
def console()
system "irb -r ./init"
end
desc "notes", "List TODO notes"
def notes
system 'grep -r "# TODO" app'
end
private
def self.source_root
File.dirname(__FILE__)
end
def target_file_for(example_file)
example_file.sub(".example", "")
end
def verify_config(env)
verify "config/settings.example.yml"
verify "config/redis/#{env}.example.conf"
end
def verify(example)
copy_example(example) unless File.exists?(target_file_for(example))
end
def redis_start
unless File.exists?(REDIS_PID)
system "redis-server #{REDIS_CNF}"
if $?.success?
say_status :success, "Redis started"
else
say_status :error, "Redis failed to start"
say_status :solution, "Make sure Redis is installed correctly and redis-server is available. The configuration files are located in config/redis."
exit(1)
end
end
end
def redis_stop
if File.exists?(REDIS_PID)
say_status :success, "Redis stopped"
system "kill #{File.read(REDIS_PID)}"
system "rm #{REDIS_PID}"
end
end
end