diff --git a/src/packer/core.clj b/src/packer/core.clj index ff7db21..1d561b8 100644 --- a/src/packer/core.clj +++ b/src/packer/core.clj @@ -30,10 +30,22 @@ "\n" (produce-items items nights i18n)))) +(defn validate-profile [store profile] + (let [all-items (->> store + vals + flatten + (map :key)) + missing-items (remove (set all-items) profile) + missing-items-str (clojure.string/join ", " missing-items)] + (when (not (empty? missing-items)) + (throw (Exception. (str "The following keys are found in the profile, but they are not defined in store: " missing-items-str)))))) + (defn produce [store profile nights i18n] - (->> store - keys - (map (fn [category] [category (filter #(.contains profile (:key %)) (get store category))])) - (filter #(not (empty? (second %)))) - (map #(produce-category (first %) (second %) nights i18n)) - (clojure.string/join "\n\n"))) \ No newline at end of file + (do + (validate-profile store profile) + (->> store + keys + (map (fn [category] [category (filter #(.contains profile (:key %)) (get store category))])) + (filter #(not (empty? (second %)))) + (map #(produce-category (first %) (second %) nights i18n)) + (clojure.string/join "\n\n")))) \ No newline at end of file