-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
criterias.clj
60 lines (42 loc) · 1.33 KB
/
criterias.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(ns polylith.clj.core.path-finder.criterias
(:require [clojure.string :as str]))
(defn =name [entity-name]
(fn [entry] (= entity-name (:name entry))))
(defn component? [{:keys [type]}]
(= :component type))
(defn base? [{:keys [type]}]
(= :base type))
(defn brick? [{:keys [type]}]
(or (= :base type)
(= :component type)))
(defn project? [{:keys [type]}]
(= :project type))
(defn src? [{:keys [test?]}]
(not test?))
(defn test? [{:keys [test?]}]
test?)
(defn exists? [{:keys [exists?]}]
exists?)
(defn not-exists? [{:keys [exists?]}]
(not exists?))
(defn src-path? [{:keys [path]}]
(str/ends-with? path "/src"))
(defn test-path? [{:keys [path]}]
(str/ends-with? path "/test"))
(defn resources-path? [{:keys [path]}]
(str/ends-with? path "/resources"))
(defn not-test-or-resources-path [entry]
(and (not (test-path? entry))
(not (resources-path? entry))))
(defn profile? [{:keys [profile?]}]
profile?)
(defn not-profile? [{:keys [profile?]}]
(not profile?))
(defn match? [path-entry criterias]
(every? true? ((apply juxt criterias) path-entry)))
(defn filter-entries [path-entries criterias]
(if (empty? criterias)
(vec path-entries)
(vec (filter #(match? % criterias) path-entries))))
(defn has-entry? [path-entries criterias]
(-> (filter-entries path-entries criterias) empty? not))