Back
load-hierarchy (clj)
(source)function
(load-hierarchy)
(load-hierarchy path)
Search the base classpath for all resources that share the same
path (by default `integrant/hierarchy.edn`), and use their contents
to extend the global `derive` hierarchy. This allows a hierarchy to be
constructed without needing to load every namespace.
The hierarchy resources should be edn files that map child keywords
to vectors of parents. For example:
{:example/child [:example/father :example/mother]}
This is equivalent:
(derive :example/child :example/father)
(derive :example/child :example/mother)
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-hierarchy-test
(try
(ig/load-hierarchy)
(is (isa? :example/child :example/father))
(is (isa? :example/child :example/mother))
(finally
(underive :example/child :example/father)
(underive :example/child :example/mother)))))
duct-framework/core
(ns duct.core-test
(:require [clojure.java.io :as io]
[clojure.test :refer :all]
[duct.core :as core]
[duct.core.merge :as merge]
[integrant.core :as ig]))
(deftest test-load-hierarchy
(core/load-hierarchy)
(is (isa? :duct/server :duct/daemon))
(is (isa? :duct.server/http :duct/server)))
(deftest test-profile-keyword
(core/load-hierarchy)
(let [m {:duct.profile/base {::a 1, ::b (ig/ref ::a)}
[:duct/profile ::x] {::a 2, ::c (ig/refset ::b)}}
p (ig/prep m)]
(is (= p
{:duct.profile/base {::a 1, ::b (core/->InertRef ::a)}
[:duct/profile ::x] {::a 2, ::c (core/->InertRefSet ::b)
::core/requires (ig/refset :duct.profile/base)}}))
(is (= (core/fold-modules (ig/init p))
{::a 2, ::b (ig/ref ::a), ::c (ig/refset ::b)}))))
(deftest test-build-config
(core/load-hierarchy)
(let [m {:duct.profile/base {::a 1, ::b (ig/ref ::a)}
[:duct/profile ::x] {::a 2, ::c (ig/refset ::b)}
[:duct/profile ::y] {::d 3}}]
(is (= (core/build-config m)
{::a 2, ::b (ig/ref ::a), ::c (ig/refset ::b), ::d 3}))
(is (= (core/build-config m [::x])
{::a 2, ::b (ig/ref ::a), ::c (ig/refset ::b)}))
(is (= (core/build-config m [:y])
{::a 1, ::b (ig/ref ::a), ::d 3}))))
(deftest test-environment-keyword
(core/load-hierarchy)
(let [m {::core/environment :development}]
(is (= m (ig/init m)))))
(deftest test-project-ns-keyword
(core/load-hierarchy)
(let [m {::core/project-ns 'foo}]
(is (= m (ig/init m)))))
(deftest test-profile-dev-keyword
(core/load-hierarchy)
(let [m {:duct.profile/base {::a 1, ::b (ig/ref ::a)}
:duct.profile/dev {::a 2, ::c (ig/refset ::b)}}
p (ig/prep m)]
(is (= p
{:duct.profile/base {::a 1, ::b (core/->InertRef ::a)}
:duct.profile/dev {::a 2, ::c (core/->InertRefSet ::b)
::core/requires (ig/refset :duct.profile/base)
::core/environment :development}}))
(is (= (core/fold-modules (ig/init p))
{::a 2, ::b (ig/ref ::a), ::c (ig/refset ::b)
::core/environment :development}))))
(deftest test-profile-test-keyword
(core/load-hierarchy)
(let [m {:duct.profile/base {::a 1, ::b (ig/ref ::a)}
:duct.profile/test {::a 2, ::c (ig/refset ::b)}}
p (ig/prep m)]
(is (= p
{:duct.profile/base {::a 1, ::b (core/->InertRef ::a)}
:duct.profile/test {::a 2, ::c (core/->InertRefSet ::b)
::core/requires (ig/refset :duct.profile/base)
::core/environment :test}}))
(is (= (core/fold-modules (ig/init p))
{::a 2, ::b (ig/ref ::a), ::c (ig/refset ::b)
::core/environment :test}))))
(deftest test-profile-prod-keyword
(core/load-hierarchy)
(let [m {:duct.profile/base {::a 1, ::b (ig/ref ::a)}
:duct.profile/prod {::a 2, ::c (ig/refset ::b)}}
p (ig/prep m)]
(is (= p
{:duct.profile/base {::a 1, ::b (core/->InertRef ::a)}
:duct.profile/prod {::a 2, ::c (core/->InertRefSet ::b)
::core/requires (ig/refset :duct.profile/base)
::core/environment :production}}))
(is (= (core/fold-modules (ig/init p))
{::a 2, ::b (ig/ref ::a), ::c (ig/refset ::b)
::core/environment :production}))))
(deftest test-module-key
(core/load-hierarchy)
(let [m {:duct.profile/base {}
::module {:route/resource :person}}
p (duct.core/prep-config m)]
(is (= :person (::foo p)))))
(deftest test-non-module-key-exception
(core/load-hierarchy)
(let [m {:duct.profile/base {}
::inc 123}
p (try (duct.core/prep-config m) (catch Exception e (ex-data e)))]
(is (= {:key ::inc} p))))
kawasima/darzana
(ns darzana.command.mapper-test
(:require [integrant.core :as ig]
[duct.core :as duct]
[darzana.command.mapper :as sut]
[darzana.api-spec.swagger]
[darzana.validator.hibernate-validator]
[darzana.runtime :as runtime]
[clojure.test :refer :all]))
(duct/load-hierarchy)
kawasima/darzana
(ns darzana.command.api-test
(:require [integrant.core :as ig]
[duct.core :as duct]
[darzana.api-spec.swagger :as swagger]
[darzana.http-client :as http]
[darzana.runtime :as runtime]
[darzana.command.api :as sut]
[cheshire.core :as json]
[clojure.test :refer :all]))
(duct/load-hierarchy)
kawasima/darzana
(ns darzana.api-spec.swagger-test
(:require [clojure.test :refer :all]
[integrant.core :as ig]
[duct.core :as duct]
[darzana.context :as context]
[darzana.runtime :as runtime]
[darzana.api-spec :as api-spec]
[darzana.api-spec.swagger :as swagger]))
(duct/load-hierarchy)
kakao/duct-lacinia
(ns duct.module.lacinia-test
(:require [duct.module.lacinia :refer :all]
[clojure.test :refer :all]
[duct.core :as core]
[integrant.core :as ig]))
(core/load-hierarchy)