forked from bcg/em-mongo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
89 lines (69 loc) · 1.68 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
require 'rake'
require 'rake/gempackagetask'
require 'spec/rake/spectask'
require 'fileutils'
task :default => :spec
class MongoRunner
def self.mongo_db_dir
"/tmp/mongo_db/"
end
def self.dtach_socket
'/tmp/mongo.dtach'
end
def self.init
FileUtils.mkdir(mongo_db_dir) if not File.exists?(mongo_db_dir)
FileUtils.rm_r Dir.glob("#{mongo_db_dir}/*")
self.stop if File.exists?("#{mongo_db_dir}/mongod.lock")
end
def self.running?
File.exists? dtach_socket
end
def self.start
self.init
puts 'Detach with Ctrl+\ Re-attach with rake mongodb:attach'
sleep 2
exec "dtach -A #{dtach_socket} mongod run -vvvvvvv --objcheck --dbpath #{mongo_db_dir}"
end
def self.start_detached
self.init
system "dtach -n #{dtach_socket} mongod run -vvvvvvvv --objcheck --logpath #{mongo_db_dir}/../mongodb.log --dbpath #{mongo_db_dir}"
end
def self.attach
exec "dtach -a #{dtach_socket}"
end
def self.stop
system "cat #{mongo_db_dir}/mongod.lock | xargs kill"
end
end
spec = eval(File.read('em-mongo.gemspec'))
Rake::GemPackageTask.new(spec) do |pkg|
pkg.gem_spec = spec
end
namespace :mongodb do
desc "start mongodb"
task :start do
MongoRunner.start
end
desc "start mongodb in the background"
task :start_detached do
MongoRunner.start_detached
end
desc "stop mongodb"
task :stop do
MongoRunner.stop
end
end
desc "rspec tests"
task :spec do
exec "bundle exec spec spec/*.rb -b -fs -color"
end
desc "run specs against mongodb"
task :test do
begin
Rake::Task["mongodb:start_detached"].invoke
sleep 1
Rake::Task["spec"].invoke
ensure
Rake::Task["mongodb:stop"].invoke
end
end