1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00
sinatra/rack-protection/Rakefile

46 lines
1.2 KiB
Text
Raw Normal View History

2012-12-12 04:22:30 -05:00
# encoding: utf-8
2011-05-23 04:07:54 -04: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'
content = File.read 'rack-protection.gemspec'
2012-12-12 04:22:30 -05:00
# fetch data
2011-05-23 04:07:54 -04:00
fields = {
:authors => `git shortlog -sn`.scan(/[^\d\s].*/),
:email => `git shortlog -sne`.scan(/[^<]+@[^>]+/),
:files => `git ls-files`.split("\n").reject { |f| f =~ /^(\.|Gemfile)/ }
}
2012-12-12 04:22:30 -05:00
# insert data
2011-05-23 04:07:54 -04: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 04:22:30 -05:00
# set version
2011-05-23 04:07:54 -04:00
content.sub! /(s\.version.*=\s+).*/, "\\1\"#{Rack::Protection::VERSION}\""
2012-12-12 04:22:30 -05:00
# escape unicode
content.gsub!(/./) { |c| c.bytesize > 1 ? "\\u{#{c.codepoints.first.to_s(16)}}" : c }
2011-05-23 04:07:54 -04:00
File.open('rack-protection.gemspec', 'w') { |f| f << content }
end
task :gemspec => 'rack-protection.gemspec'
task :default => :spec
task :test => :spec