Minor refactoring.
This commit is contained in:
parent
1b2adb5296
commit
21220970a8
|
@ -117,37 +117,36 @@
|
|||
:fault fault
|
||||
:narrative (messages fault)))
|
||||
|
||||
(defmacro nil-if-empty
|
||||
"if `x` is an empty collection, return `nil`; else return `x`."
|
||||
[x]
|
||||
`(if (coll? ~x)
|
||||
(if (empty? ~x) nil ~x)
|
||||
~x))
|
||||
|
||||
(defn object-faults
|
||||
"Return a list of faults found in object `x`, or `nil` if none are."
|
||||
[x]
|
||||
(let [faults (remove
|
||||
empty?
|
||||
(nil-if-empty
|
||||
(remove empty?
|
||||
(list
|
||||
(when-not (map? x)
|
||||
(make-fault-object
|
||||
:critical
|
||||
:not-an-object))
|
||||
(make-fault-object :critical :not-an-object))
|
||||
(when-not
|
||||
(has-context? x)
|
||||
(make-fault-object
|
||||
:should
|
||||
:no-context))
|
||||
(make-fault-object :should :no-context))
|
||||
(when-not (:type x)
|
||||
(make-fault-object
|
||||
:minor
|
||||
:no-type))
|
||||
(make-fault-object :minor :no-type))
|
||||
(when-not (and (map? x) (contains? x :id))
|
||||
(make-fault-object
|
||||
:minor
|
||||
:no-id-transient))))]
|
||||
(if (empty? faults) nil faults)))
|
||||
(make-fault-object :minor :no-id-transient))))))
|
||||
|
||||
(defn persistent-object-faults
|
||||
"Return a list of faults found in persistent object `x`, or `nil` if none are."
|
||||
[x]
|
||||
(let [faults (concat
|
||||
(object-faults x)
|
||||
(nil-if-empty
|
||||
(remove empty?
|
||||
(concat
|
||||
(object-faults x)
|
||||
(list
|
||||
(if (contains? x :id)
|
||||
(try (let [id (URI. (:id x))]
|
||||
|
@ -157,6 +156,5 @@
|
|||
(make-fault-object :must :id-not-uri))
|
||||
(catch NullPointerException _
|
||||
(make-fault-object :must :null-id-persistent)))
|
||||
(make-fault-object :must :no-id-persistent)))))]
|
||||
(if (empty? faults) nil faults)))
|
||||
(make-fault-object :must :no-id-persistent)))))))
|
||||
|
||||
|
|
Loading…
Reference in a new issue