Skip to content

Commit

Permalink
Support reader conditional when reading/merging data_readers
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-ghelardi committed Sep 2, 2023
1 parent d1d28d6 commit 8fefbe0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Changed

- Use the newly created function misc/read-data to read/merge data_readers instead of the misc/read-edn function. The former preserves reader conditionals [#31](https://github.com/nubank/vessel/pull/31).

## [0.2.146] - 2023-08-10

- Resources with the extension `.edn` are deep merged together: [#29](https://github.com/nubank/vessel/pull/29).
Expand Down
12 changes: 12 additions & 0 deletions src/vessel/misc.clj
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@
[input]
(edn/read-string (slurp input)))

(defn read-data
"Reads one object from the provided input.
input can be any object supported by clojure.core/slurp.
Note: this function is meant to be used to parse objects from
data_readers files."
[input]
(binding [*read-eval* false]
(read-string {:read-cond :preserve :features #{:clj}}
(slurp input))))

(defn read-json
"Reads a JSON object and parses it as Clojure data.
Expand Down
3 changes: 1 addition & 2 deletions src/vessel/resource_merge.clj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
data_readers.clj/cljc - merged together
*.edn - deep merged together"
[{:match-fn #(re-find #"/data_readers.cljc?$" (.getPath ^File %))
:read-fn misc/read-edn
:read-fn misc/read-data
:merge-fn merge
:write-fn write-edn}
{:match-fn #(.endsWith ".edn" (.getPath ^File %))
Expand Down Expand Up @@ -104,4 +104,3 @@
(assoc result target-file classpath-root)))
{}
(-> merge-set ::*merged-paths deref)))

5 changes: 5 additions & 0 deletions test/unit/vessel/misc_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@
(is (= {:greeting "Hello!"}
(misc/read-edn (StringReader. "{:greeting \"Hello!\"}")))))

(deftest read-data-test
(is (= {'x (reader-conditional '(:clj foo.bar/x-clj :cljs foo.bar/x-cljs) false)}
(misc/read-data
(StringReader. "{x #?(:clj foo.bar/x-clj :cljs foo.bar/x-cljs)}")))))

(deftest read-json-test
(is (= {:greeting "Hello!"}
(misc/read-json (StringReader. "{\"greeting\" : \"Hello!\"}")))))
Expand Down

0 comments on commit 8fefbe0

Please sign in to comment.