-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
96 lines (79 loc) · 2.09 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
require 'bundler'
require 'rake'
Bundler::GemHelper.install_tasks
require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end
require 'rcov/rcovtask'
Rcov::RcovTask.new do |test|
test.libs << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
test.rcov_opts << '--exclude "gems/*"'
end
task :default => :test
#todo this is wrong!
require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "terrimporter #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
namespace :version do
namespace :bump do
desc "Bump major version"
task :major do
bump_version :major
end
desc "Bump minor version"
task :minor do
bump_version :minor
end
desc "Bump patch version"
task :patch do
bump_version :patch
end
end
def bump_version(version_to_bump)
puts "Pumping version"
version = version?
case version_to_bump
when :major
version[:major] = version[:major].to_i + 1
when :minor
version[:minor] = version[:minor].to_i + 1
when :patch
version[:patch] = version[:patch].to_i + 1
end
puts "New version; " + version_string(version)
write_version(version)
end
def version_file_path
File.join(File.dirname(__FILE__), 'lib', 'terrimporter', 'version.rb')
end
def version?
pattern = /(\d+).(\d+).(\d+)/
version = nil
version_file = File.read(version_file_path)
version_file.scan(pattern) do |match|
version = {:major => match[0], :minor => match[1], :patch => match[2]}
end
version
end
def version_string(version)
"#{version[:major]}.#{version[:minor]}.#{version[:patch]}"
end
def write_version(version={})
version_rb = %Q{#Generated by rake task, last bump: #{version.to_s}
module TerrImporter
VERSION = "#{version_string version}"
end
}
File.open(version_file_path, 'w') { |f| f.write(version_rb) }
end
end