Back

prep-key (clj)

(source)

multimethod

(prep-key key value)
Prepare the configuration associated with a key for initiation. This is generally used to add in default values and references. By default the method returns the value unaltered.

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))

  (testing "custom prep-key"
    (is (= (ig/prep {::p {:b 2}, ::a 1})
           {::p {:a (ig/ref ::a), :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))
penpot/penpot
(ns app.tasks.file-xlog-gc
  "A maintenance task that performs a garbage collection of the file
  change (transaction) log."
  (:require
   [app.common.logging :as l]
   [app.db :as db]
   [app.util.time :as dt]
   [clojure.spec.alpha :as s]
   [integrant.core :as ig]))

(defmethod ig/prep-key ::handler
  [_ cfg]
  (assoc cfg ::min-age (dt/duration {:hours 72})))
TechEmpower/FrameworkBenchmarks
(ns io.github.kit-clj.te-bench.db.sql.hikari
  (:require
    [integrant.core :as ig]
    [kit.edge.db.sql.hikari]))

(defmethod ig/prep-key :db.sql/hikari-connection
  [_ config]
  (let [cpus (.availableProcessors (Runtime/getRuntime))]
    (assoc config :maximum-pool-size (* 8 cpus))))
duct-framework/duct
{{=<< >>=}}
(ns <<namespace>>.service.example
  (:require [duct.logger :as log]
            [integrant.core :as ig]))

(defmethod ig/prep-key :<<namespace>>.service/example [_ options]
  (merge {:logger (ig/ref :duct/logger)} options))
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))