Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 151 lines (125 sloc) 3.77 kB
a03e656 @holman add rakegem
holman authored
1 require 'rubygems'
2 require 'rake'
3 require 'date'
4
5 #############################################################################
6 #
7 # Helper functions
8 #
9 #############################################################################
10
11 def name
12 @name ||= Dir['*.gemspec'].first.split('.').first
13 end
14
15 def version
16 line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17 line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18 end
19
20 def date
21 Date.today.to_s
22 end
23
24 def rubyforge_project
25 name
26 end
27
28 def gemspec_file
29 "#{name}.gemspec"
30 end
31
32 def gem_file
33 "#{name}-#{version}.gem"
34 end
35
36 def replace_header(head, header_name)
37 head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
38 end
39
40 #############################################################################
41 #
42 # Standard tasks
43 #
44 #############################################################################
45
46 task :default => :test
47
48 require 'rake/testtask'
49 Rake::TestTask.new(:test) do |test|
50 test.libs << 'lib' << 'test'
51 test.pattern = 'test/**/test_*.rb'
52 test.verbose = true
53 end
54
55 desc "Generate RCov test coverage and open in your browser"
56 task :coverage do
57 require 'rcov'
58 sh "rm -fr coverage"
59 sh "rcov test/test_*.rb"
60 sh "open coverage/index.html"
61 end
62
63 require 'rake/rdoctask'
64 Rake::RDocTask.new do |rdoc|
65 rdoc.rdoc_dir = 'rdoc'
66 rdoc.title = "#{name} #{version}"
67 rdoc.rdoc_files.include('README*')
68 rdoc.rdoc_files.include('lib/**/*.rb')
69 end
70
71 desc "Open an irb session preloaded with this library"
72 task :console do
73 sh "irb -rubygems -r ./lib/#{name}.rb"
74 end
75
76 #############################################################################
77 #
78 # Custom tasks (add your own tasks here)
79 #
80 #############################################################################
81
82
83
84 #############################################################################
85 #
86 # Packaging tasks
87 #
88 #############################################################################
89
90 desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
91 task :release => :build do
92 unless `git branch` =~ /^\* master$/
93 puts "You must be on the master branch to release!"
94 exit!
95 end
96 sh "git commit --allow-empty -a -m 'Release #{version}'"
97 sh "git tag v#{version}"
98 sh "git push origin master"
99 sh "git push origin v#{version}"
100 sh "gem push pkg/#{name}-#{version}.gem"
101 end
102
103 desc "Build #{gem_file} into the pkg directory"
104 task :build => :gemspec do
105 sh "mkdir -p pkg"
106 sh "gem build #{gemspec_file}"
107 sh "mv #{gem_file} pkg"
108 end
109
110 desc "Generate #{gemspec_file}"
111 task :gemspec => :validate do
112 # read spec file and split out manifest section
113 spec = File.read(gemspec_file)
114 head, manifest, tail = spec.split(" # = MANIFEST =\n")
115
116 # replace name version and date
117 replace_header(head, :name)
118 replace_header(head, :version)
119 replace_header(head, :date)
120 #comment this out if your rubyforge_project has a different name
6ba48df @markburns hmmm, how do i change this gem name
authored
121 #replace_header(head, :rubyforge_project)
a03e656 @holman add rakegem
holman authored
122
123 # determine file list from git ls-files
124 files = `git ls-files`.
125 split("\n").
126 sort.
127 reject { |file| file =~ /^\./ }.
128 reject { |file| file =~ /^(rdoc|pkg)/ }.
129 map { |file| " #{file}" }.
130 join("\n")
131
132 # piece file back together and write
133 manifest = " s.files = %w[\n#{files}\n ]\n"
134 spec = [head, manifest, tail].join(" # = MANIFEST =\n")
135 File.open(gemspec_file, 'w') { |io| io.write(spec) }
136 puts "Updated #{gemspec_file}"
137 end
138
139 desc "Validate #{gemspec_file}"
140 task :validate do
141 libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
142 unless libfiles.empty?
143 puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
144 exit!
145 end
146 unless Dir['VERSION*'].empty?
147 puts "A `VERSION` file at root level violates Gem best practices."
148 exit!
149 end
150 end
Something went wrong with that request. Please try again.