Skip to content

Commit

Permalink
simplify package structure part #5: muuntaja
Browse files Browse the repository at this point in the history
  • Loading branch information
Krisztian Gulyas committed Oct 1, 2021
1 parent 1e00c54 commit b50057d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
7 changes: 0 additions & 7 deletions src/xiana/interceptor.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
[clojure.walk :refer [keywordize-keys]]
[ring.middleware.params :as middleware.params]
[xiana.core :as xiana]
[xiana.interceptor.muuntaja :as muuntaja]
[xiana.interceptor.wrap :as wrap]
[xiana.session :as session])
(:import
(java.util
Expand Down Expand Up @@ -127,8 +125,3 @@
(f state role)
;; associate authorization into session-data
(assoc-in [:session-data :authorization] auth)))))}))

(defn muuntaja
"Muuntaja encoder/decoder interceptor."
([] (muuntaja muuntaja/interceptor))
([interceptor] (wrap/interceptor interceptor)))
12 changes: 8 additions & 4 deletions src/xiana/interceptor/muuntaja.clj → src/xiana/muuntaja.clj
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
(ns xiana.interceptor.muuntaja
(ns xiana.muuntaja
"Muuntaja interceptor encoder/decode.."
(:require
[clojure.data.xml :as xml]
[clojure.string]
[muuntaja.core]
[muuntaja.format.core]
[muuntaja.format.json :as json]
[muuntaja.interceptor]))
[muuntaja.interceptor]
[xiana.interceptor.wrap :as wrap]))

(defn xml-encoder
"XML encoder."
Expand Down Expand Up @@ -39,6 +40,9 @@
(assoc-in [:formats "application/json" :encoder-opts :date-format]
"yyyy-MM-dd"))))

(def interceptor
(defn interceptor
"Define muuntaja's default interceptor."
(muuntaja.interceptor/format-interceptor instance))
([]
(wrap/interceptor (muuntaja.interceptor/format-interceptor instance)))
([interceptor]
(wrap/interceptor interceptor)))
5 changes: 3 additions & 2 deletions test/xiana/interceptor_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[clojure.test :refer [deftest is]]
[xiana.core :as xiana]
[xiana.db :as db]
[xiana.interceptor :as interceptor]))
[xiana.interceptor :as interceptor]
[xiana.muuntaja :as muuntaja]))

(def sample-session-id
"Sample session id."
Expand Down Expand Up @@ -156,5 +157,5 @@
(nil? (get-in simple-resp [:session-data :authorization]))))))

(deftest contains-muuntaja-interceptor
(let [interceptor (interceptor/muuntaja)]
(let [interceptor (muuntaja/interceptor)]
(is (not (empty? interceptor)))))
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(ns xiana.interceptor.muuntaja-test
(ns xiana.muuntaja-test
(:require
[clojure.test :refer [deftest is]]
[muuntaja.format.core :as format]
[xiana.interceptor.muuntaja :as muuntaja]))
[xiana.muuntaja :as muuntaja]))

(def data-sample [["note" "anything" "note"]])

Expand Down

0 comments on commit b50057d

Please sign in to comment.