-
Notifications
You must be signed in to change notification settings - Fork 176
/
coerce.clj
44 lines (41 loc) · 1.53 KB
/
coerce.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(ns cider.nrepl.middleware.util.coerce
"Coercion utilities for coercing bencoded maps.")
(defn- update-some
[m k & args]
(if (get m k)
(apply update m k args)
m))
(defn ns-query
"Poke and prod at a bencoded ns-query until it is in the form that orchard
expects."
[ns-query]
(-> ns-query
(update-some :exactly
#(seq
(map (fn [ns-string]
(if-let [ns (find-ns (symbol ns-string))]
ns
(throw (ex-info "Namespace not found"
{::id :namespace-not-found
:namespace-string ns-string}))))
%)))
(update :project? some?)
(update :load-project-ns? (fn [x]
(cond
(= x []) false
:else (some? x))))
(update :has-tests? some?)
(update-some :include-regexps #(map re-pattern %))
(update-some :exclude-regexps #(map re-pattern %))))
(defn var-query
[var-query]
(-> var-query
(update :ns-query ns-query)
(update-some :exactly #(seq (keep (comp find-var symbol) %)))
(update :test? some?)
(update :private? some?)
(update-some :include-meta-key #(map keyword %))
(update-some :exclude-meta-key #(map keyword %))
(update-some :search re-pattern)
(update-some :search-property keyword)
(dissoc :manipulate-vars)))