11 SRC_FILES = FileList["#{SRC_DIR}/*"]
12 KOAN_FILES = SRC_FILES.pathmap("#{PROB_DIR}/%f")
14 today = Time.now.strftime("%Y-%m-%d")
15 TAR_FILE = "#{DIST_DIR}/rubykoans-#{today}.tgz"
16 ZIP_FILE = "#{DIST_DIR}/rubykoans-#{today}.zip"
18 CLEAN.include("**/*.rbc")
19 CLOBBER.include(DIST_DIR)
22 extend Rake::DSL if defined?(Rake::DSL)
24 # Remove solution info from source
28 def Koans.remove_solution(line)
29 line = line.gsub(/\b____\([^\)]+\)/, "____")
30 line = line.gsub(/\b___\([^\)]+\)/, "___")
31 line = line.gsub(/\b__\([^\)]+\)/, "__")
32 line = line.gsub(/\b_n_\([^\)]+\)/, "_n_")
33 line = line.gsub(%r(/\#\{__\}/), "/__/")
34 line = line.gsub(/\s*#\s*__\s*$/, '')
38 def Koans.make_koan_file(infile, outfile)
39 if infile =~ /edgecase/
41 elsif infile =~ /autotest/
45 open(outfile, "w") do |outs|
48 state = :skip if line =~ /^ *#--/
51 outs.puts remove_solution(line)
55 state = :copy if line =~ /^ *#\+\+/
64 # Calculate the list of relevant Ruby implementations.
65 def self.find_ruby_impls
66 rubys = `rvm list`.gsub(/=>/,'').split(/\n/).sort
68 last = rubys.grep(Regexp.new(Regexp.quote(impl))).last
69 last ? last.split.first : nil
73 # Return a (cached) list of relevant Ruby implementations.
75 @list ||= find_ruby_impls
78 # List of expected ruby implementations.
80 %w(ruby-1.8.6 ruby-1.8.7 ruby-1.9.2 jruby ree)
84 task :default => :walk_the_path
86 task :walk_the_path do
88 ruby 'path_to_enlightenment.rb'
91 Rake::RDocTask.new do |rd|
92 rd.main = "README.rdoc"
93 rd.rdoc_files.include("README.rdoc", "koans/*.rb")
99 file ZIP_FILE => KOAN_FILES + [DIST_DIR] do
100 sh "zip #{ZIP_FILE} #{PROB_DIR}/*"
103 file TAR_FILE => KOAN_FILES + [DIST_DIR] do
104 sh "tar zcvf #{TAR_FILE} #{PROB_DIR}"
107 desc "Create packaged files for distribution"
108 task :package => [TAR_FILE, ZIP_FILE]
110 desc "Upload the package files to the web server"
111 task :upload => [TAR_FILE, ZIP_FILE] do
112 sh "scp #{TAR_FILE} linode:sites/onestepback.org/download"
113 sh "scp #{ZIP_FILE} linode:sites/onestepback.org/download"
116 desc "Generate the Koans from the source files from scratch."
117 task :regen => [:clobber_koans, :gen]
119 desc "Generate the Koans from the changed source files."
120 task :gen => KOAN_FILES + [PROB_DIR + "/README.rdoc"]
121 task :clobber_koans do
125 file PROB_DIR + "/README.rdoc" => "README.rdoc" do |t|
126 cp "README.rdoc", t.name
129 SRC_FILES.each do |koan_src|
130 file koan_src.pathmap("#{PROB_DIR}/%f") => [PROB_DIR, koan_src] do |t|
131 Koans.make_koan_file koan_src, t.name
139 sh "ruby path_to_enlightenment.rb"
144 desc "Pre-checkin tests (=> run_all)"
145 task :cruise => :run_all
147 desc "Run the completed koans againts a list of relevant Ruby Implementations"
150 RubyImpls.list.each do |impl|
152 puts "On Ruby #{impl}"
153 sh "rvm #{impl} rake run"
154 results << [impl, "RAN"]
160 results.each do |impl, res|
161 puts "#{impl} => RAN"
164 RubyImpls.expected.each do |requested_impl|
165 impl_pattern = Regexp.new(Regexp.quote(requested_impl))
166 puts "No Results for #{requested_impl}" unless results.detect { |x| x.first =~ impl_pattern }