Back
prep (clj)
(source)function
(prep config)
(prep config keys)
Prepare a config map for initiation. The prep-key method is applied to each
entry in the map, and the values replaced with the return value. This is used
for adding default values and references to the configuration.
Examples
integrant
(ns integrant.core-test
(:require #?(:clj [clojure.test :refer [are deftest is testing]]
:cljs [cljs.test :refer-macros [are deftest is testing]])
[integrant.core :as ig]
[weavejester.dependency :as dep]))
(defmethod ig/prep-key ::p [_ v]
(merge {:a (ig/ref ::a)} v))
(deftest prep-test
(testing "default"
(is (= (ig/prep {::q {:b 2}, ::a 1})
{::q {:b 2}, ::a 1})))
(testing "custom prep-key"
(is (= (ig/prep {::p {:b 2}, ::a 1})
{::p {:a (ig/ref ::a), :b 2}, ::a 1})))
(testing "prep then init"
(is (= (ig/init (ig/prep {::p {:b 2}, ::a 1}))
{::p [{:a [1], :b 2}], ::a [1]}))))
penpot/penpot
(ns app.tasks.tasks-gc
"A maintenance task that performs a cleanup of already executed tasks
from the database table."
(:require
[app.common.logging :as l]
[app.config :as cf]
[app.db :as db]
[clojure.spec.alpha :as s]
[integrant.core :as ig]))
(defmethod ig/prep-key ::handler
[_ cfg]
(assoc cfg ::min-age cf/deletion-delay))
kit-clj/kit
(ns kit.edge.utils.repl
(:require
[clojure.core.server :as socket]
[clojure.tools.logging :as log]
[integrant.core :as ig]))
(defmethod ig/prep-key :repl/server
[_ config]
(merge {:name "main"} config))
duct-framework/module.web
(ns duct.handler.root
(:require [integrant.core :as ig]))
(defmethod ig/prep-key :duct.handler/root [_ config]
(merge {:router (ig/ref :duct/router)} config))
jacekschae/learn-datomic-course-files
(ns cheffy.ion
(:require [integrant.core :as ig]
[cheffy.components.auth0 :as auth0]
[cheffy.components.datomic-cloud :as datomic-cloud]
[datomic.ion :as ion]
[cheffy.server :as server]))
(def handler
(-> integrant-setup ig/prep ig/init ::server/app))
dpom/nlp-tools
(ns nlptools.tool.stemmer
(:require
[clojure.spec.alpha :as s]
[clojure.test :refer :all]
[stemmer.snowball :as snowball]
[integrant.core :as ig]
[duct.logger :refer [log]]
[nlpcore.protocols :as core]
[nlpcore.spec :as nsp]
[nlptools.tool.core :as tool]
[nlptools.command :as cmd]))
(deftest apply-tool-test
(let [config (merge (cmd/make-test-logger :error)
{ukey {:id "tets stemmer"
:language "ro"
:logger (ig/ref :duct.logger/timbre)}})
system (ig/init (cmd/prep-igconfig config))
stemmer (get system ukey)
res (core/apply-tool stemmer "copiilor" {})]
(is (s/valid? ::result res))
(is (= "cop" res))))
(defmethod cmd/run cmdkey [_ options summary]
(let [opts (cmd/set-config options)
{:keys [language text] :or {text ""}} opts
config (merge (cmd/make-logger opts)
{ukey {:id "run stemmer"
:language language
:logger (ig/ref :duct.logger/timbre)}})
system (ig/init (cmd/prep-igconfig config))
stemmer (get system ukey)]
(printf "word: %s,\nstem: %s\n" text (core/apply-tool stemmer text {}))
(ig/halt! system)
0))