-
Notifications
You must be signed in to change notification settings - Fork 8
/
Rakefile
118 lines (98 loc) · 2.78 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# -*- coding: utf-8 -*-
###
RELEASE = ENV['rel'] || '0.0.0'
COPYRIGHT = 'copyright(c) 2014-2016 kuwata-lab.com all rights reserved'
LICENSE = 'MIT License'
PROJECT = 'keight'
###
task :default => :test
def edit_content(content)
s = content
s = s.gsub /\$Release\:.*?\$/, "$Release\: #{RELEASE} $"
s = s.gsub /\$Copyright\:.*?\$/, "$Copyright\: #{COPYRIGHT} $"
s = s.gsub /\$License\:.*?\$/, "$License\: #{LICENSE} $"
s = s.gsub /\$Release\$/, RELEASE
s = s.gsub /\$Copyright\$/, COPYRIGHT
s = s.gsub /\$License\$/, LICENSE
s
end
desc "run test scripts"
task :test do
#sh "ruby -r minitest/autorun test/*_test.rb"
sh "ruby test/#{PROJECT}_test.rb -ss"
end
desc "remove *.rbc"
task :clean do
rm_f [Dir.glob("lib/**/*.rbc"), Dir.glob("test/**/*.rbc")]
end
desc "copy files into 'dist/#{RELEASE}'"
task :dist => :clean do
require_release_number()
spec_src = File.open("#{PROJECT}.gemspec") {|f| f.read }
spec = eval spec_src
dir = "dist/#{RELEASE}"
rm_rf dir
mkdir_p dir
sh "tar cf - #{spec.files.join(' ')} | (cd #{dir}; tar xvf -)"
spec.files.each do |fpath|
next if fpath =~ /\.(gz|jpg|png|form)\z/
#filepath = File.join(dir, fpath)
#content = File.open(filepath, 'rb:utf-8') {|f| f.read }
#new_content = edit_content(content)
#File.open(filepath, 'wb:utf-8') {|f| f.write(new_content) }
content = File.open(File.join(dir, fpath), 'r+b:utf-8') do |f|
content = f.read
new_content = edit_content(content)
f.rewind()
f.truncate(0)
f.write(new_content)
end
end
end
desc "create rubygem pacakge"
task :package => :dist do
require_release_number()
chdir "dist/#{RELEASE}" do
sh "gem build *.gemspec"
end
mv Dir.glob("dist/#{RELEASE}/*.gem"), 'dist'
end
desc "release gem"
task :release => :package do
require_release_number()
sh "git tag ruby-#{RELEASE}"
chdir "dist" do
sh "gem push #{PROJECT}-#{RELEASE}.gem"
end
end
def require_release_number
if RELEASE == '0.0.0'
$stderr.puts "*** Release number is not speicified"
$stderr.puts "*** Usage: rake <task> rel=X.X.X"
raise StandardError
end
end
task :http_status_codes do
require 'open-uri'
url = "https://en.wikipedia.org/wiki/List_of_HTTP_status_codes"
content = open(url) {|f| f.read }
#File.open("/tmp/http_status_code", 'w') {|f| f.write(content) }
#content = File.open("/tmp/http_status_code", 'rb') {|f| f.read }
lines = []
content.scan(/>(\d\d\d)\s+(.*?)<\/dt>/) do |code, text|
desc = nil
if text =~ /(.*?)\s+\((.*?)\)/
text = $1
desc = $2
desc = desc.gsub(/<a .*?>(.*?)<\/a>/, '\1')
end
text = text.sub(/<\/a>/, '')
line = " #{code} => \"#{text}\","
if desc
line = "%-50s # %s" % [line, desc]
end
lines << line
end
lines.sort!
puts lines
end