Back

load-namespaces (clj)

(source)

function

(load-namespaces config) (load-namespaces config keys)
Attempt to load the namespaces referenced by the keys in a configuration. If a key is namespaced, both the namespace and the namespace concatenated with the name will be tried. For example, if a key is :foo.bar/baz, then the function will attempt to load the namespaces foo.bar and foo.bar.baz. Upon completion, a list of all loaded namespaces will be returned.

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

#?(:clj
   (deftest load-namespaces-test
     (testing "all namespaces"
       (remove-lib 'integrant.test.foo)
       (remove-lib 'integrant.test.bar)
       (remove-lib 'integrant.test.baz)
       (remove-lib 'integrant.test.quz)
       (is (= (set (ig/load-namespaces
                    {:integrant.test/foo                     1
                     :integrant.test.bar/wuz                 2
                     [:integrant.test/baz :integrant.test/x] 3
                     [:integrant.test/y :integrant.test/quz] 4}))
              '#{integrant.test.foo
                 integrant.test.bar
                 integrant.test.baz
                 integrant.test.quz}))
       (is (some? (find-ns 'integrant.test.foo)))
       (is (some? (find-ns 'integrant.test.bar)))
       (is (some? (find-ns 'integrant.test.baz)))
       (is (some? (find-ns 'integrant.test.quz)))
       (is (= (some-> 'integrant.test.foo/message find-var var-get) "foo"))
       (is (= (some-> 'integrant.test.bar/message find-var var-get) "bar"))
       (is (= (some-> 'integrant.test.baz/message find-var var-get) "baz"))
       (is (= (some-> 'integrant.test.quz/message find-var var-get) "quz")))

     (testing "some namespaces"
       (remove-lib 'integrant.test.foo)
       (remove-lib 'integrant.test.bar)
       (remove-lib 'integrant.test.baz)
       (remove-lib 'integrant.test.quz)
       (is (= (set (ig/load-namespaces
                    {:integrant.test/foo 1
                     :integrant.test/bar (ig/ref :integrant.test/foo)
                     :integrant.test/baz 3}
                    [:integrant.test/bar]))
              '#{integrant.test.foo
                 integrant.test.bar}))
       (is (some? (find-ns 'integrant.test.foo)))
       (is (some? (find-ns 'integrant.test.bar)))
       (is (nil?  (find-ns 'integrant.test.baz))))

     (testing "load namespaces of ancestors"
       (remove-lib 'integrant.test.foo)
       (is (= (set (ig/load-namespaces
                    {:integrant.test-child/foo 1}))
              '#{integrant.test.foo}))
       (is (some? (find-ns 'integrant.test.foo))))))
jacekschae/learn-datomic-course-files
(ns user
  (:require [integrant.repl :as ig-repl]
            [integrant.core :as ig]
            [integrant.repl.state :as state]
            [datomic.client.api :as d]))

(ig-repl/set-prep!
  (fn []
    (let [config (-> "config/dev.edn" slurp ig/read-string)]
      (ig/load-namespaces config)
      config)))

  (cheffy.auth0/get-management-token (-> state/system :cheffy.components.auth0/auth))
  (ig/load-namespaces
    (-> "config/dev.edn" slurp ig/read-string))
jacekschae/learn-datomic-course-files
(ns user
  (:require [integrant.repl :as ig-repl]
            [integrant.core :as ig]
            [integrant.repl.state :as state]
            [datomic.client.api :as d]))

(ig-repl/set-prep!
  (fn []
    (let [config (-> "config/dev.edn" slurp ig/read-string)]
      (ig/load-namespaces config)
      config)))

  (cheffy.auth0/get-management-token (-> state/system :cheffy.components.auth0/auth))
  (ig/load-namespaces
    (-> "config/dev.edn" slurp ig/read-string))
jacekschae/learn-datomic-course-files
(ns user
  (:require [integrant.repl :as ig-repl]
            [integrant.core :as ig]
            [integrant.repl.state :as state]
            [datomic.client.api :as d]))

(ig-repl/set-prep!
  (fn []
    (let [config (-> "config/dev.edn" slurp ig/read-string)]
      (ig/load-namespaces config)
      config)))

  (cheffy.auth0/get-management-token (-> state/system :cheffy.components.auth0/auth))
  (ig/load-namespaces
    (-> "config/dev.edn" slurp ig/read-string))
jacekschae/learn-datomic-course-files
(ns user
  (:require [integrant.repl :as ig-repl]
            [integrant.core :as ig]
            [integrant.repl.state :as state]
            [datomic.client.api :as d]))

(ig-repl/set-prep!
  (fn []
    (let [config (-> "config/dev.edn" slurp ig/read-string)]
      (ig/load-namespaces config)
      config)))

  (cheffy.auth0/get-management-token (-> state/system :cheffy.components.auth0/auth))
  (ig/load-namespaces
    (-> "config/dev.edn" slurp ig/read-string))
jacekschae/learn-datomic-course-files
(ns user
  (:require [integrant.repl :as ig-repl]
            [integrant.core :as ig]
            [integrant.repl.state :as state]
            [datomic.client.api :as d]))

(ig-repl/set-prep!
  (fn []
    (let [config (-> "config/dev.edn" slurp ig/read-string)]
      (ig/load-namespaces config)
      config)))

  (cheffy.auth0/get-management-token (-> state/system :cheffy.components.auth0/auth))
  (ig/load-namespaces
    (-> "config/dev.edn" slurp ig/read-string))