8 # No rdoc task availble.
15 SRC_FILES = FileList["#{SRC_DIR}/*"]
16 KOAN_FILES = SRC_FILES.pathmap("#{PROB_DIR}/%f")
18 today = Time.now.strftime("%Y-%m-%d")
19 TAR_FILE = "#{DIST_DIR}/rubykoans-#{today}.tgz"
20 ZIP_FILE = "#{DIST_DIR}/rubykoans-#{today}.zip"
22 CLEAN.include("**/*.rbc")
23 CLOBBER.include(DIST_DIR)
26 extend Rake::DSL if defined?(Rake::DSL)
28 # Remove solution info from source
32 def Koans.remove_solution(line)
33 line = line.gsub(/\b____\([^\)]+\)/, "____")
34 line = line.gsub(/\b___\([^\)]+\)/, "___")
35 line = line.gsub(/\b__\([^\)]+\)/, "__")
36 line = line.gsub(/\b_n_\([^\)]+\)/, "_n_")
37 line = line.gsub(%r(/\#\{__\}/), "/__/")
38 line = line.gsub(/\s*#\s*__\s*$/, '')
42 def Koans.make_koan_file(infile, outfile)
43 if infile =~ /edgecase/
47 open(outfile, "w") do |outs|
50 state = :skip if line =~ /^ *#--/
53 outs.puts remove_solution(line)
57 state = :copy if line =~ /^ *#\+\+/
66 # Calculate the list of relevant Ruby implementations.
67 def self.find_ruby_impls
68 rubys = `rvm list`.gsub(/=>/,'').split(/\n/).map { |x| x.strip }.reject { |x| x.empty? || x =~ /^rvm/ }.sort
70 last = rubys.grep(Regexp.new(Regexp.quote(impl))).last
71 last ? last.split.first : nil
75 # Return a (cached) list of relevant Ruby implementations.
77 @list ||= find_ruby_impls
80 # List of expected ruby implementations.
82 %w(ruby-1.8.7 ruby-1.9.2 jruby ree)
86 task :default => :walk_the_path
88 task :walk_the_path do
90 ruby 'path_to_enlightenment.rb'
93 if defined?(Rake::RDocTask)
94 Rake::RDocTask.new do |rd|
95 rd.main = "README.rdoc"
96 rd.rdoc_files.include("README.rdoc", "${PROB_DIR}/*.rb")
103 file ZIP_FILE => KOAN_FILES + [DIST_DIR] do
104 sh "zip #{ZIP_FILE} #{PROB_DIR}/*"
107 file TAR_FILE => KOAN_FILES + [DIST_DIR] do
108 sh "tar zcvf #{TAR_FILE} #{PROB_DIR}"
111 desc "Create packaged files for distribution"
112 task :package => [TAR_FILE, ZIP_FILE]
114 desc "Upload the package files to the web server"
115 task :upload => [TAR_FILE, ZIP_FILE] do
116 sh "scp #{TAR_FILE} linode:sites/onestepback.org/download"
117 sh "scp #{ZIP_FILE} linode:sites/onestepback.org/download"
120 desc "Generate the Koans from the source files from scratch."
121 task :regen => [:clobber_koans, :gen]
123 desc "Generate the Koans from the changed source files."
124 task :gen => KOAN_FILES + [PROB_DIR + "/README.rdoc"]
125 task :clobber_koans do
129 file PROB_DIR + "/README.rdoc" => "README.rdoc" do |t|
130 cp "README.rdoc", t.name
133 SRC_FILES.each do |koan_src|
134 file koan_src.pathmap("#{PROB_DIR}/%f") => [PROB_DIR, koan_src] do |t|
135 Koans.make_koan_file koan_src, t.name
141 Dir.chdir("${SRC_DIR}") do
143 sh "ruby path_to_enlightenment.rb"
148 desc "Pre-checkin tests (=> run_all)"
149 task :cruise => :run_all
151 desc "Run the completed koans againts a list of relevant Ruby Implementations"
154 RubyImpls.list.each do |impl|
156 puts "On Ruby #{impl}"
157 sh ". rvm #{impl}; rake run"
158 results << [impl, "RAN"]
164 results.each do |impl, res|
165 puts "#{impl} => RAN"
168 RubyImpls.expected.each do |requested_impl|
169 impl_pattern = Regexp.new(Regexp.quote(requested_impl))
170 puts "No Results for #{requested_impl}" unless results.detect { |x| x.first =~ impl_pattern }