Skip to content

Commit e5e60e7

Browse files
authored
Merge pull request excon#652 from djberg96/rakefile
[WIP] Clean up Rakefile
2 parents 0770d18 + 3f513b3 commit e5e60e7

File tree

1 file changed

+13
-139
lines changed

1 file changed

+13
-139
lines changed

Rakefile

+13-139
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,18 @@
1-
require 'rubygems'
2-
require 'rake'
3-
require 'date'
4-
include Rake::DSL
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}/version.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-
461
require 'shindo/rake'
47-
require "rspec/core/rake_task"
48-
49-
RSpec::Core::RakeTask.new(:spec, :format) do |t, args|
50-
format = args[:format] || 'doc'
51-
t.rspec_opts = ["-c", "-f #{format}", "-r ./spec/spec_helper.rb"]
52-
t.pattern = 'spec/**/*_spec.rb'
53-
end
54-
55-
56-
Shindo::Rake.new
57-
58-
task :default => [ :tests, :test]
59-
task :test => :spec
60-
2+
require 'rspec/core/rake_task'
3+
require 'bundler/gem_tasks'
614
require 'rdoc/task'
62-
Rake::RDocTask.new do |rdoc|
63-
rdoc.rdoc_dir = 'rdoc'
64-
rdoc.title = "#{name} #{version}"
65-
rdoc.rdoc_files.include('README*')
66-
rdoc.rdoc_files.include('lib/**/*.rb')
67-
end
685

69-
desc "Open an irb session preloaded with this library"
70-
task :console do
71-
sh "irb -rubygems -r ./lib/#{name}.rb"
72-
end
73-
74-
#############################################################################
75-
#
76-
# Custom tasks (add your own tasks here)
77-
#
78-
#############################################################################
79-
80-
81-
82-
#############################################################################
83-
#
84-
# Packaging tasks
85-
#
86-
#############################################################################
87-
88-
task :release => [:update_certs, :build] do
89-
unless `git branch` =~ /^\* master$/
90-
puts "You must be on the master branch to release!"
91-
exit!
92-
end
93-
sh "gem install pkg/#{name}-#{version}.gem"
94-
sh "git commit --allow-empty -a -m 'Release #{version}'"
95-
sh "git tag v#{version}"
96-
sh "git push origin master"
97-
sh "git push origin v#{version}"
98-
sh "gem push pkg/#{name}-#{version}.gem"
99-
end
100-
101-
task :build => :gemspec do
102-
sh "mkdir -p pkg"
103-
sh "gem build #{gemspec_file}"
104-
sh "mv #{gem_file} pkg"
105-
end
106-
107-
task :gemspec => :validate do
108-
# read spec file and split out manifest section
109-
spec = File.read(gemspec_file)
110-
head, manifest, tail = spec.split(" # = MANIFEST =\n")
111-
112-
# replace name version and date
113-
replace_header(head, :name)
114-
replace_header(head, :version)
115-
replace_header(head, :date)
116-
#comment this out if your rubyforge_project has a different name
117-
replace_header(head, :rubyforge_project)
118-
119-
# determine file list from git ls-files
120-
files = `git ls-files`.
121-
split("\n").
122-
sort.
123-
reject { |file| file =~ /^\./ }.
124-
reject { |file| file =~ /^(rdoc|pkg)/ }.
125-
map { |file| " #{file}" }.
126-
join("\n")
6+
Shindo::Rake.new
1277

128-
# piece file back together and write
129-
manifest = " s.files = %w[\n#{files}\n ]\n"
130-
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
131-
File.open(gemspec_file, 'w') { |io| io.write(spec) }
132-
puts "Updated #{gemspec_file}"
8+
RSpec::Core::RakeTask.new(:spec, :format) do |t, args|
9+
format = args[:format] || 'doc'
10+
t.rspec_opts = ["-c", "-f #{format}", "-r ./spec/spec_helper.rb"]
11+
t.pattern = 'spec/**/*_spec.rb'
13312
end
13413

135-
task :validate do
136-
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
137-
unless libfiles.empty?
138-
puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
139-
exit!
140-
end
141-
unless Dir['VERSION*'].empty?
142-
puts "A `VERSION` file at root level violates Gem best practices."
143-
exit!
144-
end
145-
end
14+
task :default => [:tests, :test]
15+
task :test => :spec
14616

14717
desc "update bundled certs"
14818
task :update_certs do
@@ -158,6 +28,10 @@ task :update_certs do
15828
sh "openssl req -subj '/CN=127.0.0.1/O=excon' -new -newkey rsa:2048 -sha256 -days 365 -nodes -x509 -keyout tests/data/127.0.0.1.cert.key -out tests/data/127.0.0.1.cert.crt"
15929
end
16030

31+
desc "Open an irb session preloaded with this library"
32+
task :console do
33+
sh "irb -rubygems -r ./lib/#{name}.rb"
34+
end
16135

16236
desc "check ssl settings"
16337
task :hows_my_ssl do

0 commit comments

Comments
 (0)