forked from sinatra/rack-protection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
48 lines (38 loc) · 1.32 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
# encoding: utf-8
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
begin
require 'bundler'
Bundler::GemHelper.install_tasks
rescue LoadError => e
$stderr.puts e
end
desc "run specs"
task(:spec) { ruby '-S rspec spec' }
desc "generate gemspec"
task 'rack-protection.gemspec' do
require 'rack/protection/version'
content = File.binread 'rack-protection.gemspec'
# fetch data
fields = {
:authors => `git shortlog -sn`.force_encoding('utf-8').scan(/[^\d\s].*/),
:email => `git shortlog -sne`.force_encoding('utf-8').scan(/[^<]+@[^>]+/),
:files => `git ls-files`.force_encoding('utf-8').split("\n").reject { |f| f =~ /^(\.|Gemfile)/ }
}
# double email :(
fields[:email].delete("konstantin.haase@gmail.com")
# insert data
fields.each do |field, values|
updated = " s.#{field} = ["
updated << values.map { |v| "\n %p" % v }.join(',')
updated << "\n ]"
content.sub!(/ s\.#{field} = \[\n( .*\n)* \]/, updated)
end
# set version
content.sub! /(s\.version.*=\s+).*/, "\\1\"#{Rack::Protection::VERSION}\""
# escape unicode
content.gsub!(/./) { |c| c.bytesize > 1 ? "\\u{#{c.codepoints.first.to_s(16)}}" : c }
File.open('rack-protection.gemspec', 'w') { |f| f << content }
end
task :gemspec => 'rack-protection.gemspec'
task :default => :spec
task :test => :spec