This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def ^:dynamic *config* nil) | |
(defn save [data & {:keys [config] :or {config *config*}}] | |
(println (format "Saved %s with %s" data config))) | |
;; => (save {:a 5 :b 6} :config {:some :config}) | |
;; Saved {:a 5, :b 6} with {:some :config} | |
;; nil | |
;; => (binding [*config* {:some :config}] (save {:a 5 :b 6})) | |
;; Saved {:a 5, :b 6} with {:some :config} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the LazyDict implementation, callable values are evaluated before returning them | |
class LazyDict(dict): | |
def __getitem__(self, k): | |
val = dict.__getitem__(self, k) | |
if callable(val): | |
val = val() | |
self[k] = val | |
return val | |
# creates lambdas of all the dict entries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns db-fixture | |
(:require [config :as config]) | |
(:import (org.testcontainers.containers GenericContainer | |
BindMode))) | |
(defn create-db-container [{:keys [dbname user password]}] | |
(-> (GenericContainer. "postgres:12.2") | |
(.withExposedPorts (into-array Integer [(int 5432)])) | |
(.withEnv "POSTGRES_DB" dbname) | |
(.withEnv "POSTGRES_USER" user) |