/
Rakefile
188 lines (161 loc) · 4.95 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
require 'rake'
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "mongo_doc_rails2"
gem.summary = %Q{ODM for MongoDB - for Rails 2.3.x}
gem.description = %Q{ODM for MongoDB - for Rails 2.3.x}
gem.email = "leshill@gmail.com"
gem.homepage = "http://github.com/leshill/mongodoc"
gem.authors = ["Les Hill"]
gem.add_dependency "activesupport", ">= 2.3.4"
gem.add_dependency "mongo", ">= 1.0.1"
gem.add_dependency "bson", ">= 1.0.1"
gem.add_dependency "bson_ext", ">= 1.0.1"
gem.add_dependency "durran-validatable", "= 2.0.1"
gem.add_dependency "leshill-will_paginate", "= 2.3.11"
gem.add_development_dependency "rspec", "= 1.3.0"
gem.add_development_dependency "cucumber", ">= 0.6.2"
end
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end
require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:features) do |t|
t.cucumber_opts = "--format pretty --tag ~@wip"
end
namespace :cucumber do
Cucumber::Rake::Task.new(:wip) do |t|
t.cucumber_opts = "--format pretty --tag @wip"
end
end
require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:spec) do |spec|
spec.spec_opts = ['--options', "#{File.expand_path(File.dirname(__FILE__))}/spec/spec.opts"]
spec.libs << 'lib' << 'spec'
spec.spec_files = FileList['spec/**/*_spec.rb']
end
Spec::Rake::SpecTask.new(:rcov) do |spec|
spec.spec_opts = ['--options', "#{File.expand_path(File.dirname(__FILE__))}/spec/spec.opts"]
spec.libs << 'lib' << 'spec'
spec.pattern = 'spec/**/*_spec.rb'
spec.rcov = true
end
task :spec => :check_dependencies
task :default => :spec
require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
if File.exist?('VERSION')
version = File.read('VERSION')
else
version = ""
end
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "MongoDoc #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
namespace :mongo do
desc 'Start mongod'
task :start do
default_config = { "dbpath" => "/data/db" }
config = begin
YAML.load_file(File.join(File.dirname(__FILE__), 'mongod.yml'))
rescue Exception => e
{}
end
config = default_config.merge(config)
sh("nohup #{config['mongod'] || 'mongod'} --dbpath #{config['dbpath']} &")
puts "\n"
end
end
namespace :mongoid do
desc 'Sync criteria from Mongoid'
task :sync do
require 'pathname'
src_dir = Pathname.new('../durran-mongoid/lib/mongoid')
dest_dir = Pathname.new('lib/mongoid')
dest_dir.mkpath
%w(criteria.rb contexts/paging.rb contexts/enumerable.rb criterion extensions/symbol/inflections.rb extensions/hash/criteria_helpers.rb matchers).each do |f|
src = src_dir + f
if src.directory?
FileUtils.cp_r(src, dest_dir)
else
dest = dest_dir + f
dest.dirname.mkpath
FileUtils.cp(src, dest)
end
end
end
end
namespace :bench do
desc 'Run benchmark for MongoDoc'
task 'mongo_doc' do
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
require 'perf/mongo_document'
benchmark("MongoDoc saving documents", MongoDocument.new)
end
desc 'Run benchmark for MongoDoc Object'
task 'mongo_object' do
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
require 'perf/mongo_doc_object'
benchmark("MongoDoc saving objects", MongoDocObject.new)
end
desc 'Run profiler for driver'
task 'driver' do
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
require 'perf/ruby_driver'
benchmark("Ruby driver saving hashes", RubyDriver.new)
end
end
namespace :prof do
desc 'Run profiler for MongoDoc'
task 'mongo_doc' do
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
require 'perf/mongo_document'
profile("MongoDoc saving documents", MongoDocument.new)
end
desc 'Run profiler for MongoDoc Object'
task 'mongo_object' do
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
require 'perf/mongo_doc_object'
profile("MongoDoc saving objects", MongoDocObject.new)
end
desc 'Run profiler for driver'
task 'driver' do
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
require 'perf/ruby_driver'
profile("Ruby driver saving hashes", RubyDriver.new)
end
def benchmark(what, runner)
puts "Benchmark: " + what
runner.generate(10000)
Benchmark.bm do |bm|
bm.report(what + " writes") do
runner.writes(10000)
end
end
Benchmark.bm do |bm|
bm.report(what + " reads") do
runner.reads(10000)
end
end
Benchmark.bm do |bm|
bm.report(what + " query") do
runner.query_all
end
end
end
def profile(what, runner)
puts "Profiling: " + what
RubyProf.start
runner.generate(1000)
runner.writes(1000)
runner.reads(1000)
runner.query_all
result = RubyProf.stop
printer = RubyProf::FlatPrinter.new(result)
printer.print(STDOUT, 0)
end
end