Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 127 lines (106 sloc) 3.192 kb
079d4a0 @darkhelmet Initial commit to rack-mongrel2.
darkhelmet authored
1 require 'rubygems'
2 require 'rake'
18c3973 @darkhelmet Convert to rakegem, removing jeweler
darkhelmet authored
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
6c166a9 Getting this to play nice with 'gem which'
Nathan Duran authored
16 line = File.read("lib/khi-rack-mongrel2.rb")[/^\s*VERSION\s*=\s*.*/]
18c3973 @darkhelmet Convert to rakegem, removing jeweler
darkhelmet authored
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)}'"}
079d4a0 @darkhelmet Initial commit to rack-mongrel2.
darkhelmet authored
38 end
39
18c3973 @darkhelmet Convert to rakegem, removing jeweler
darkhelmet authored
40 #############################################################################
41 #
42 # Standard tasks
43 #
44 #############################################################################
45
4105345 @darkhelmet Convert Rakefile to rakegem style, and remove Jeweler
darkhelmet authored
46 task :default => :spec
18c3973 @darkhelmet Convert to rakegem, removing jeweler
darkhelmet authored
47
4105345 @darkhelmet Convert Rakefile to rakegem style, and remove Jeweler
darkhelmet authored
48 require 'rspec/core/rake_task'
49 RSpec::Core::RakeTask.new(:spec) do |t|
50 t.ruby_opts = ['-Ilib', '-Ispec']
51 t.pattern = 'spec/**/*_spec.rb'
18c3973 @darkhelmet Convert to rakegem, removing jeweler
darkhelmet authored
52 end
53
54 desc "Open an irb session preloaded with this library"
55 task :console do
56 sh "irb -rubygems -r ./lib/#{name}.rb"
57 end
58
59 #############################################################################
60 #
61 # Custom tasks (add your own tasks here)
62 #
63 #############################################################################
64
4105345 @darkhelmet Convert Rakefile to rakegem style, and remove Jeweler
darkhelmet authored
65 begin
66 require 'yard'
67 YARD::Rake::YardocTask.new
68 rescue LoadError
69 task :yardoc do
70 abort 'YARD is not available. In order to run yardoc, you must: `gem i yard`'
71 end
079d4a0 @darkhelmet Initial commit to rack-mongrel2.
darkhelmet authored
72 end
73
18c3973 @darkhelmet Convert to rakegem, removing jeweler
darkhelmet authored
74 #############################################################################
75 #
76 # Packaging tasks
77 #
78 #############################################################################
79
80 desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
81 task :release => :build do
82 unless `git branch` =~ /^\* master$/
83 puts "You must be on the master branch to release!"
84 exit!
079d4a0 @darkhelmet Initial commit to rack-mongrel2.
darkhelmet authored
85 end
18c3973 @darkhelmet Convert to rakegem, removing jeweler
darkhelmet authored
86 sh "git commit --allow-empty -a -m 'Release #{version}'"
87 sh "git tag v#{version}"
88 sh "git push origin master"
89 sh "git push origin v#{version}"
90 sh "gem push pkg/#{name}-#{version}.gem"
91 end
92
93 desc "Build #{gem_file} into the pkg directory"
94 task :build => :gemspec do
95 sh "mkdir -p pkg"
96 sh "gem build #{gemspec_file}"
97 sh "mv #{gem_file} pkg"
98 end
99
100 desc "Generate #{gemspec_file}"
101 task :gemspec do
102 # read spec file and split out manifest section
103 spec = File.read(gemspec_file)
104 head, manifest, tail = spec.split(" # = MANIFEST =\n")
105
106 # replace name version and date
107 replace_header(head, :name)
108 replace_header(head, :version)
109 replace_header(head, :date)
110 #comment this out if your rubyforge_project has a different name
111 replace_header(head, :rubyforge_project)
112
113 # determine file list from git ls-files
114 files = `git ls-files`.
115 split("\n").
116 sort.
117 reject { |file| file =~ /^\./ }.
118 reject { |file| file =~ /^(rdoc|pkg)/ }.
119 map { |file| " #{file}" }.
120 join("\n")
121
122 # piece file back together and write
123 manifest = " s.files = %w[\n#{files}\n ]\n"
124 spec = [head, manifest, tail].join(" # = MANIFEST =\n")
125 File.open(gemspec_file, 'w') { |io| io.write(spec) }
126 puts "Updated #{gemspec_file}"
8cc561a @darkhelmet get things going
darkhelmet authored
127 end
Something went wrong with that request. Please try again.