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 # Remove solution info from source
26 def Koans.remove_solution(line)
27 line = line.gsub(/\b____\([^\)]+\)/, "____")
28 line = line.gsub(/\b___\([^\)]+\)/, "___")
29 line = line.gsub(/\b__\([^\)]+\)/, "__")
30 line = line.gsub(/\b_n_\([^\)]+\)/, "_n_")
31 line = line.gsub(%r(/\#\{__\}/), "/__/")
32 line = line.gsub(/\s*#\s*__\s*$/, '')
36 def Koans.make_koan_file(infile, outfile)
37 if infile =~ /edgecase/
39 elsif infile =~ /autotest/
43 open(outfile, "w") do |outs|
46 state = :skip if line =~ /^ *#--/
49 outs.puts remove_solution(line)
53 state = :copy if line =~ /^ *#\+\+/
62 # Calculate the list of relevant Ruby implementations.
63 def self.find_ruby_impls
64 rubys = `rvm list`.gsub(/=>/,'').split(/\n/).sort
66 last = rubys.grep(Regexp.new(Regexp.quote(impl))).last
67 last ? last.split.first : nil
71 # Return a (cached) list of relevant Ruby implementations.
73 @list ||= find_ruby_impls
76 # List of expected ruby implementations.
78 %w(ruby-1.8.6 ruby-1.8.7 ruby-1.9.2 jruby ree)
82 task :default => :walk_the_path
84 task :walk_the_path do
86 ruby 'path_to_enlightenment.rb'
89 Rake::RDocTask.new do |rd|
90 rd.main = "README.rdoc"
91 rd.rdoc_files.include("README.rdoc", "koans/*.rb")
97 file ZIP_FILE => KOAN_FILES + [DIST_DIR] do
98 sh "zip #{ZIP_FILE} #{PROB_DIR}/*"
101 file TAR_FILE => KOAN_FILES + [DIST_DIR] do
102 sh "tar zcvf #{TAR_FILE} #{PROB_DIR}"
105 desc "Create packaged files for distribution"
106 task :package => [TAR_FILE, ZIP_FILE]
108 desc "Upload the package files to the web server"
109 task :upload => [TAR_FILE, ZIP_FILE] do
110 sh "scp #{TAR_FILE} linode:sites/onestepback.org/download"
111 sh "scp #{ZIP_FILE} linode:sites/onestepback.org/download"
114 desc "Generate the Koans from the source files from scratch."
115 task :regen => [:clobber_koans, :gen]
117 desc "Generate the Koans from the changed source files."
118 task :gen => KOAN_FILES + [PROB_DIR + "/README.rdoc"]
119 task :clobber_koans do
123 file PROB_DIR + "/README.rdoc" => "README.rdoc" do |t|
124 cp "README.rdoc", t.name
127 SRC_FILES.each do |koan_src|
128 file koan_src.pathmap("#{PROB_DIR}/%f") => [PROB_DIR, koan_src] do |t|
129 Koans.make_koan_file koan_src, t.name
137 sh "ruby path_to_enlightenment.rb"
142 desc "Pre-checkin tests (=> run_all)"
143 task :cruise => :run_all
145 desc "Run the completed koans againts a list of relevant Ruby Implementations"
148 RubyImpls.list.each do |impl|
150 puts "On Ruby #{impl}"
151 sh "rvm #{impl} rake run"
152 results << [impl, "RAN"]
158 results.each do |impl, res|
159 puts "#{impl} => RAN"
162 RubyImpls.expected.each do |requested_impl|
163 impl_pattern = Regexp.new(Regexp.quote(requested_impl))
164 puts "No Results for #{requested_impl}" unless results.detect { |x| x.first =~ impl_pattern }