Skip to content

Commit af7bf2c

Browse files
authored
Merge pull request #5 from juxt/master
update
2 parents 3460edb + 7031ec0 commit af7bf2c

File tree

3 files changed

+32
-33
lines changed

3 files changed

+32
-33
lines changed

README.md

+22-22
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Aero provides a small library of tag literals.
9797
Use `#env` to reference an environment variable.
9898

9999
```clojure
100-
{:password #env DATABASE_URI}
100+
{:database-uri #env DATABASE_URI}
101101
```
102102

103103
It is considered bad practice to use environment variables for passwords and other confidential information. This is because it is very easy for anyone to read a process's environment (e.g. via `ps -ef`). Environment variables are also commonly dumped out in a debugging sessions. Instead you should use `#include` - see [here](#hide-passwords-in-local-private-files).
@@ -115,7 +115,7 @@ Use `#envf` to insert environment variables into a formatted string.
115115
Use `#or` when you want to provide a list of possibilities, perhaps with a default and the end.
116116

117117
```clojure
118-
{:password #or [#env PORT 8080]}
118+
{:port #or [#env PORT 8080]}
119119
```
120120

121121
### join
@@ -133,7 +133,7 @@ Use `#or` when you want to provide a list of possibilities, perhaps with a defau
133133

134134
Use profile as a kind of reader conditional.
135135

136-
`#profile` expects a map, from which is extracts the entry corresponding to the of __profile__.
136+
`#profile` expects a map, from which it extracts the entry corresponding to the __profile__.
137137

138138
```clojure
139139
{:webserver
@@ -220,37 +220,37 @@ Merge multiple maps together
220220
#merge [{:foo :bar} {:foo :zip}]
221221
```
222222

223-
### Define your own
224-
225-
Aero supports user-defined tag literals. Just extend the `reader` multimethod.
226-
227-
```clojure
228-
(defmethod reader `mytag
229-
[{:keys [profile] :as opts} tag value]
230-
(if (= value :favorite)
231-
:chocolate
232-
:vanilla))
233-
```
234-
235-
## Using `^:ref` metadata for references
223+
### ref
236224

237-
To avoid duplication you can refer to other parts of you configuration file using `^:ref` metadata.
225+
To avoid duplication you can refer to other parts of your configuration file using the `#ref` tag.
238226

239-
The `^:ref` value should be a vector resolveable by `get-in`. Take the following config map for example:
227+
The `#ref` value should be a vector resolveable by `get-in`. Take the following config map for example:
240228

241229
```clojure
242230
{:db-connection "datomic:dynamo://dynamodb"
243231
:webserver
244-
{:db ^:ref [:db-connection]}
232+
{:db #ref [:db-connection]}
245233
:analytics
246-
{:db ^:ref [:db-connection]}}
234+
{:db #ref [:db-connection]}}
247235
```
248236

249237
Both `:analytics` and `:webserver` will have their `:db` keys resolved
250238
to `"datomic:dynamo://dynamodb"`
251239

252240
References are recursive. They can be used in `#include` files.
253241

242+
### Define your own
243+
244+
Aero supports user-defined tag literals. Just extend the `reader` multimethod.
245+
246+
```clojure
247+
(defmethod reader 'mytag
248+
[{:keys [profile] :as opts} tag value]
249+
(if (= value :favorite)
250+
:chocolate
251+
:vanilla))
252+
```
253+
254254
## Deferreds
255255

256256
Sometimes you may not want your tag literal to be run during the EDN load, but only after the tree has fully loaded.
@@ -277,8 +277,8 @@ Here is how this can be achieved:
277277
{:secrets #include #join [#env HOME "/.secrets.edn"]
278278

279279
:aws-secret-access-key
280-
#profile {:test ^:ref [:secrets :aws-test-key]
281-
:prod ^:ref [:secrets :aws-prod-key]}}
280+
#profile {:test #ref [:secrets :aws-test-key]
281+
:prod #ref [:secrets :aws-prod-key]}}
282282
```
283283

284284
### Use functions to wrap access to your configuration.

project.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;; Copyright © 2015, JUXT LTD.
22

3-
(defproject aero "1.1.2"
3+
(defproject aero "1.1.3"
44
:description "A small library for explicit, intentful configuration."
55
:url "https://github.com/juxt/aero"
66
:license {:name "The MIT License"

src/aero/core.cljc

+9-10
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@
1010
[aero.vendor.dependency.v0v2v0.com.stuartsierra.dependency :as dep]))
1111
#?(:clj (:import (java.io StringReader)))
1212
#?(:cljs (:require [cljs.tools.reader :as edn]
13-
[cljs.nodejs :as nodejs]
1413
[goog.string :as gstring]
1514
goog.string.format
1615
[clojure.walk :refer [walk postwalk]]
17-
[aero.vendor.dependency.v0v2v0.com.stuartsierra.dependency :as dep])))
16+
[aero.vendor.dependency.v0v2v0.com.stuartsierra.dependency :as dep]
17+
["os" :as os]
18+
["fs" :as fs]
19+
["path" :as path])))
1820

1921
(declare read-config)
2022

21-
#?(:cljs (def os (nodejs/require "os")))
22-
#?(:cljs (def fs (nodejs/require "fs")))
23-
2423
(defmulti reader (fn [opts tag value] tag))
2524

2625
(defmethod reader :default
@@ -89,7 +88,7 @@
8988
(defmethod reader 'hostname
9089
[{:keys [hostname]} tag value]
9190
(let [hostn (or hostname #?(:clj (env "HOSTNAME")
92-
:cljs (os.hostname)))]
91+
:cljs (os/hostname)))]
9392
(or
9493
(some (fn [[k v]]
9594
(when (or (= k hostn)
@@ -125,7 +124,7 @@
125124
[opts tag value]
126125
(some-> value str edn/read-string))
127126

128-
(defmethod aero.core/reader 'merge
127+
(defmethod reader 'merge
129128
[opts tag values]
130129
(apply merge values))
131130

@@ -174,9 +173,9 @@
174173
{:profile :default
175174
:resolver #?(:clj adaptive-resolver
176175
:cljs (fn [source include]
177-
(if (path.isAbsolute include)
176+
(if (path/isAbsolute include)
178177
include
179-
(path.join source ".." include))))})
178+
(path/join source ".." include))))})
180179

181180
;; The rationale for deferreds is to realise some values after the
182181
;; config has been read. This allows certain expensive operations to
@@ -357,7 +356,7 @@
357356
;; post-processed tags with declared data readers
358357
:readers {}
359358
:default tag-wrapper}
360-
(fs.readFileSync source "utf-8"))))))
359+
(fs/readFileSync source "utf-8"))))))
361360

362361
(defn read-config
363362
"First argument is a string URL to the file. To read from the

0 commit comments

Comments
 (0)