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/
45 elsif infile =~ /autotest/
49 open(outfile, "w") do |outs|
52 state = :skip if line =~ /^ *#--/
55 outs.puts remove_solution(line)
59 state = :copy if line =~ /^ *#\+\+/
68 # Calculate the list of relevant Ruby implementations.
69 def self.find_ruby_impls
70 rubys = `rvm list`.gsub(/=>/,'').split(/\n/).map { |x| x.strip }.reject { |x| x.empty? || x =~ /^rvm/ }.sort
72 last = rubys.grep(Regexp.new(Regexp.quote(impl))).last
73 last ? last.split.first : nil
77 # Return a (cached) list of relevant Ruby implementations.
79 @list ||= find_ruby_impls
82 # List of expected ruby implementations.
84 %w(ruby-1.8.7 ruby-1.9.2 jruby ree)
88 task :default => :walk_the_path
90 task :walk_the_path do
92 ruby 'path_to_enlightenment.rb'
95 if defined?(Rake::RDocTask)
96 Rake::RDocTask.new do |rd|
97 rd.main = "README.rdoc"
98 rd.rdoc_files.include("README.rdoc", "${PROB_DIR}/*.rb")
105 file ZIP_FILE => KOAN_FILES + [DIST_DIR] do
106 sh "zip #{ZIP_FILE} #{PROB_DIR}/*"
109 file TAR_FILE => KOAN_FILES + [DIST_DIR] do
110 sh "tar zcvf #{TAR_FILE} #{PROB_DIR}"
113 desc "Create packaged files for distribution"
114 task :package => [TAR_FILE, ZIP_FILE]
116 desc "Upload the package files to the web server"
117 task :upload => [TAR_FILE, ZIP_FILE] do
118 sh "scp #{TAR_FILE} linode:sites/onestepback.org/download"
119 sh "scp #{ZIP_FILE} linode:sites/onestepback.org/download"
122 desc "Generate the Koans from the source files from scratch."
123 task :regen => [:clobber_koans, :gen]
125 desc "Generate the Koans from the changed source files."
126 task :gen => KOAN_FILES + [PROB_DIR + "/README.rdoc"]
127 task :clobber_koans do
131 file PROB_DIR + "/README.rdoc" => "README.rdoc" do |t|
132 cp "README.rdoc", t.name
135 SRC_FILES.each do |koan_src|
136 file koan_src.pathmap("#{PROB_DIR}/%f") => [PROB_DIR, koan_src] do |t|
137 Koans.make_koan_file koan_src, t.name
143 Dir.chdir("${SRC_DIR}") do
145 sh "ruby path_to_enlightenment.rb"
150 desc "Pre-checkin tests (=> run_all)"
151 task :cruise => :run_all
153 desc "Run the completed koans againts a list of relevant Ruby Implementations"
156 RubyImpls.list.each do |impl|
158 puts "On Ruby #{impl}"
159 sh ". rvm #{impl}; rake run"
160 results << [impl, "RAN"]
166 results.each do |impl, res|
167 puts "#{impl} => RAN"
170 RubyImpls.expected.each do |requested_impl|
171 impl_pattern = Regexp.new(Regexp.quote(requested_impl))
172 puts "No Results for #{requested_impl}" unless results.detect { |x| x.first =~ impl_pattern }