Split freshener and koan ordering out into namespaces.
This commit is contained in:
parent
3644a48bcd
commit
c2c9a15cea
@ -1,6 +1,8 @@
|
|||||||
(ns path-to-answer-sheet
|
(ns path-to-answer-sheet
|
||||||
(:use [path-to-enlightenment :exclude (run)]
|
(:use [runner.koans :only [ordered-koans]]
|
||||||
[clojure.string :only (join split trim)]))
|
[path-to-enlightenment :only [meditations __ ___]]
|
||||||
|
[clojure.string :only [join split trim]]
|
||||||
|
[clojure.test :only [*test-out*]]))
|
||||||
|
|
||||||
(def answers
|
(def answers
|
||||||
{"equalities" {"__" [true
|
{"equalities" {"__" [true
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
(ns path-to-enlightenment
|
(ns path-to-enlightenment
|
||||||
(:use [fresh.core :only [clj-files-in freshener]]
|
(:use [runner.freshness :only [setup-freshener]])
|
||||||
[clojure.java.io :only [file]])
|
|
||||||
(:require [clojure.set]
|
(:require [clojure.set]
|
||||||
[clojure.string]
|
[clojure.string]
|
||||||
[clojure.test])
|
[clojure.test]))
|
||||||
(:import
|
|
||||||
[java.util.concurrent ScheduledThreadPoolExecutor TimeUnit]))
|
|
||||||
|
|
||||||
(def __ :fill-in-the-blank)
|
(def __ :fill-in-the-blank)
|
||||||
(def ___ (fn [& args] __))
|
(def ___ (fn [& args] __))
|
||||||
@ -19,26 +16,6 @@
|
|||||||
pairs)]
|
pairs)]
|
||||||
`(and ~@tests)))
|
`(and ~@tests)))
|
||||||
|
|
||||||
(def ordered-koans
|
|
||||||
["equalities"
|
|
||||||
"lists"
|
|
||||||
"vectors"
|
|
||||||
"sets"
|
|
||||||
"maps"
|
|
||||||
"functions"
|
|
||||||
"conditionals"
|
|
||||||
"higher_order_functions"
|
|
||||||
"runtime_polymorphism"
|
|
||||||
"lazy_sequences"
|
|
||||||
"sequence_comprehensions"
|
|
||||||
"creating_functions"
|
|
||||||
"recursion"
|
|
||||||
"destructuring"
|
|
||||||
"refs"
|
|
||||||
"atoms"
|
|
||||||
"macros"
|
|
||||||
"datatypes"])
|
|
||||||
|
|
||||||
(defn require-version [[required-major required-minor]]
|
(defn require-version [[required-major required-minor]]
|
||||||
(let [{:keys [major minor]} *clojure-version*]
|
(let [{:keys [major minor]} *clojure-version*]
|
||||||
(if (or (< major required-major)
|
(if (or (< major required-major)
|
||||||
@ -60,54 +37,7 @@
|
|||||||
(map read-string
|
(map read-string
|
||||||
(take 3 (clojure.string/split version-string #"[\.\-]")))))
|
(take 3 (clojure.string/split version-string #"[\.\-]")))))
|
||||||
|
|
||||||
(defn files-to-keep-fresh []
|
|
||||||
(clj-files-in (file "src" "koans")))
|
|
||||||
|
|
||||||
(defn- tests-pass? [file-path]
|
|
||||||
(use 'path-to-enlightenment)
|
|
||||||
(load-file file-path))
|
|
||||||
|
|
||||||
(defn- among-paths? [files]
|
|
||||||
(into #{} (map #(.getCanonicalPath %) files)))
|
|
||||||
|
|
||||||
(defn- ordered-koan-paths []
|
|
||||||
(map (fn [koan-name]
|
|
||||||
(.getCanonicalPath (file "src" "koans" (str koan-name ".clj"))))
|
|
||||||
ordered-koans))
|
|
||||||
|
|
||||||
(defn- next-koan-path [last-koan-path]
|
|
||||||
(loop [[this-koan & more :as koan-paths] (ordered-koan-paths)]
|
|
||||||
(when (seq more)
|
|
||||||
(if (= last-koan-path this-koan)
|
|
||||||
(first more)
|
|
||||||
(recur more)))))
|
|
||||||
|
|
||||||
(defn namaste []
|
|
||||||
(println "\nYou have achieved clojure enlightenment. Namaste."))
|
|
||||||
|
|
||||||
(defn report-refresh [report]
|
|
||||||
(when-let [refreshed-files (seq (:reloaded report))]
|
|
||||||
(let [these-koans (filter
|
|
||||||
(among-paths? refreshed-files)
|
|
||||||
(ordered-koan-paths))]
|
|
||||||
(println "Refreshing:" these-koans)
|
|
||||||
(when (every? tests-pass? these-koans)
|
|
||||||
(if-let [next-koan-file (file (next-koan-path (last these-koans)))]
|
|
||||||
(report-refresh {:reloaded [next-koan-file]})
|
|
||||||
(namaste))))
|
|
||||||
(println))
|
|
||||||
:refreshed)
|
|
||||||
|
|
||||||
(def refresh! (freshener files-to-keep-fresh report-refresh))
|
|
||||||
|
|
||||||
(def scheduler (ScheduledThreadPoolExecutor. 1))
|
|
||||||
|
|
||||||
(defn setup-freshener []
|
|
||||||
(.scheduleWithFixedDelay scheduler refresh! 0 500 TimeUnit/MILLISECONDS)
|
|
||||||
(.awaitTermination scheduler Long/MAX_VALUE TimeUnit/SECONDS))
|
|
||||||
|
|
||||||
(defn run []
|
(defn run []
|
||||||
(require-version (parse-required-version))
|
(require-version (parse-required-version))
|
||||||
(setup-freshener))
|
(setup-freshener))
|
||||||
|
|
||||||
|
|
||||||
|
34
src/runner/freshness.clj
Normal file
34
src/runner/freshness.clj
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
(ns runner.freshness
|
||||||
|
(:use [fresh.core :only [clj-files-in freshener]]
|
||||||
|
[clojure.java.io :only [file]]
|
||||||
|
[runner.koans :only [among-paths?
|
||||||
|
namaste
|
||||||
|
next-koan-path
|
||||||
|
ordered-koans
|
||||||
|
ordered-koan-paths
|
||||||
|
tests-pass?]])
|
||||||
|
(:import [java.util.concurrent ScheduledThreadPoolExecutor TimeUnit]))
|
||||||
|
|
||||||
|
(defn files-to-keep-fresh []
|
||||||
|
(clj-files-in (file "src" "koans")))
|
||||||
|
|
||||||
|
(defn report-refresh [report]
|
||||||
|
(when-let [refreshed-files (seq (:reloaded report))]
|
||||||
|
(let [these-koans (filter
|
||||||
|
(among-paths? refreshed-files)
|
||||||
|
(ordered-koan-paths))]
|
||||||
|
(println "Refreshing:" these-koans)
|
||||||
|
(when (every? tests-pass? these-koans)
|
||||||
|
(if-let [next-koan-file (file (next-koan-path (last these-koans)))]
|
||||||
|
(report-refresh {:reloaded [next-koan-file]})
|
||||||
|
(namaste))))
|
||||||
|
(println))
|
||||||
|
:refreshed)
|
||||||
|
|
||||||
|
(def refresh! (freshener files-to-keep-fresh report-refresh))
|
||||||
|
|
||||||
|
(def scheduler (ScheduledThreadPoolExecutor. 1))
|
||||||
|
|
||||||
|
(defn setup-freshener []
|
||||||
|
(.scheduleWithFixedDelay scheduler refresh! 0 500 TimeUnit/MILLISECONDS)
|
||||||
|
(.awaitTermination scheduler Long/MAX_VALUE TimeUnit/SECONDS))
|
45
src/runner/koans.clj
Normal file
45
src/runner/koans.clj
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
(ns runner.koans
|
||||||
|
(:use [clojure.java.io :only [file]]))
|
||||||
|
|
||||||
|
(def ordered-koans
|
||||||
|
["equalities"
|
||||||
|
"lists"
|
||||||
|
"vectors"
|
||||||
|
"sets"
|
||||||
|
"maps"
|
||||||
|
"functions"
|
||||||
|
"conditionals"
|
||||||
|
"higher_order_functions"
|
||||||
|
"runtime_polymorphism"
|
||||||
|
"lazy_sequences"
|
||||||
|
"sequence_comprehensions"
|
||||||
|
"creating_functions"
|
||||||
|
"recursion"
|
||||||
|
"destructuring"
|
||||||
|
"refs"
|
||||||
|
"atoms"
|
||||||
|
"macros"
|
||||||
|
"datatypes"])
|
||||||
|
|
||||||
|
(defn ordered-koan-paths []
|
||||||
|
(map (fn [koan-name]
|
||||||
|
(.getCanonicalPath (file "src" "koans" (str koan-name ".clj"))))
|
||||||
|
ordered-koans))
|
||||||
|
|
||||||
|
(defn among-paths? [files]
|
||||||
|
(into #{} (map #(.getCanonicalPath %) files)))
|
||||||
|
|
||||||
|
(defn next-koan-path [last-koan-path]
|
||||||
|
(loop [[this-koan & more :as koan-paths] (ordered-koan-paths)]
|
||||||
|
(when (seq more)
|
||||||
|
(if (= last-koan-path this-koan)
|
||||||
|
(first more)
|
||||||
|
(recur more)))))
|
||||||
|
|
||||||
|
(defn tests-pass? [file-path]
|
||||||
|
(use '[path-to-enlightenment :only [meditations __ ___]])
|
||||||
|
(load-file file-path))
|
||||||
|
|
||||||
|
(defn namaste []
|
||||||
|
(println "\nYou have achieved clojure enlightenment. Namaste."))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user