Skip to content

Commit

Permalink
fix handling of null values within objects/lists.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick Scherer committed May 15, 2017
1 parent 560842e commit eea1765
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions src/alumbra/claro/values.clj
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
(ns alumbra.claro.values
(:require [alumbra.claro.coercion :as c]))

(declare process-value)
(defprotocol ClaroValue
(process-value [this opts]))

(defn- process-key
[{:keys [key-fn]} k]
(key-fn k))

(defn- process-object
[opts o]
(->> (for [[k v] o]
[(process-key opts k)
(process-value opts v)])
(into {})))
(extend-protocol ClaroValue
clojure.lang.Sequential
(process-value [sq opts]
(mapv #(process-value % opts) sq))

(defn- process-scalar
[opts {:keys [type-name value]}]
(c/coerce-value opts type-name value))
clojure.lang.IPersistentMap
(process-value [{:keys [type-name value] :as o} opts]
(if type-name
(c/coerce-value opts type-name value)
(->> (for [[k v] o]
[(process-key opts k)
(process-value v opts)])
(into {}))))

(defn process-value
[opts v]
{:pre [(or (map? v) (sequential? v))]}
(cond (sequential? v) (mapv #(process-value opts %) v)
(:type-name v) (process-scalar opts v)
:else (process-object opts v)))
Object
(process-value [this _]
(throw
(IllegalArgumentException.
(str "Unexpected value when preparing arguments: "
(pr-str this)))))

nil
(process-value [_ _]
nil))

(defn process-arguments
[opts arguments]
(process-object opts arguments))
{:pre [(map? arguments)]}
(process-value arguments opts))

0 comments on commit eea1765

Please sign in to comment.