sinatra/rack-protection/Rakefile

49 lines
1.3 KiB
Ruby
Raw Normal View History

2012-12-12 09:22:30 +00:00
# encoding: utf-8
2011-05-23 08:07:54 +00:00
$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'
2013-03-01 04:55:54 +00:00
content = File.binread 'rack-protection.gemspec'
2011-05-23 08:07:54 +00:00
2012-12-12 09:22:30 +00:00
# fetch data
2011-05-23 08:07:54 +00:00
fields = {
2013-03-01 04:55:54 +00:00
: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)/ }
2011-05-23 08:07:54 +00:00
}
2013-03-01 04:55:54 +00:00
# double email :(
fields[:email].delete("konstantin.haase@gmail.com")
2012-12-12 09:22:30 +00:00
# insert data
2011-05-23 08:07:54 +00:00
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
2012-12-12 09:22:30 +00:00
# set version
2011-05-23 08:07:54 +00:00
content.sub! /(s\.version.*=\s+).*/, "\\1\"#{Rack::Protection::VERSION}\""
2012-12-12 09:22:30 +00:00
# escape unicode
content.gsub!(/./) { |c| c.bytesize > 1 ? "\\u{#{c.codepoints.first.to_s(16)}}" : c }
2011-05-23 08:07:54 +00:00
File.open('rack-protection.gemspec', 'w') { |f| f << content }
end
task :gemspec => 'rack-protection.gemspec'
task :default => :spec
task :test => :spec