forked from norman/friendly_id
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
112 lines (92 loc) · 2.85 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
require "rubygems"
require "rake/testtask"
task :default => :test
task :load_path do
%w(lib test).each do |path|
$LOAD_PATH.unshift(File.expand_path("../#{path}", __FILE__))
end
end
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList['test/*_test.rb']
t.verbose = true
end
desc "Remove temporary files"
task :clean do
%x{rm -rf *.gem doc pkg coverage}
%x{rm -f `find . -name '*.rbc'`}
end
desc "Build the gem"
task :gem do
%x{gem build friendly_id.gemspec}
end
desc "Build YARD documentation"
task :yard => :guide do
puts %x{bundle exec yard}
end
desc "Run benchmarks"
task :bench => :load_path do
require File.expand_path("../bench", __FILE__)
end
desc "Generate Guide.rdoc"
task :guide do
def read_comments(path)
path = File.expand_path("../#{path}", __FILE__)
match = File.read(path).match(/\n=begin(.*)\n=end/m)[1].to_s
match.split("\n").reject {|x| x =~ /^@/}.join("\n")
end
buffer = []
buffer << read_comments("lib/friendly_id.rb")
buffer << read_comments("lib/friendly_id/base.rb")
buffer << read_comments("lib/friendly_id/slugged.rb")
buffer << read_comments("lib/friendly_id/history.rb")
buffer << read_comments("lib/friendly_id/scoped.rb")
buffer << read_comments("lib/friendly_id/simple_i18n.rb")
buffer << read_comments("lib/friendly_id/reserved.rb")
File.open("Guide.rdoc", "w") do |file|
file.write("#encoding: utf-8\n")
file.write(buffer.join("\n"))
end
end
namespace :test do
desc "Run each test class in a separate process"
task :isolated do
dir = File.expand_path("../test", __FILE__)
Dir["#{dir}/*_test.rb"].each do |test|
puts "Running #{test}:"
puts %x{ruby -Ilib -Itest #{test}}
end
end
end
namespace :db do
desc "Create the database"
task :create => :load_path do
require "helper"
driver = FriendlyId::Test::Database.driver
config = FriendlyId::Test::Database.config[driver]
commands = {
"mysql" => "mysql -u #{config['username']} -e 'create database #{config["database"]};' >/dev/null",
"postgres" => "psql -c 'create database #{config['database']};' -U #{config['username']} >/dev/null"
}
%x{#{commands[driver] || true}}
end
desc "Create the database"
task :drop => :load_path do
require "helper"
driver = FriendlyId::Test::Database.driver
config = FriendlyId::Test::Database.config[driver]
commands = {
"mysql" => "mysql -u #{config['username']} -e 'drop database #{config["database"]};' >/dev/null",
"postgres" => "psql -c 'drop database #{config['database']};' -U #{config['username']} >/dev/null"
}
%x{#{commands[driver] || true}}
end
desc "Set up the database schema"
task :up => :load_path do
require "helper"
FriendlyId::Test::Schema.up
end
desc "Drop and recreate the database schema"
task :reset => [:drop, :create]
end
task :doc => :yard