Skip to content

Commit

Permalink
Add middleware explanation in README
Browse files Browse the repository at this point in the history
  • Loading branch information
David Leatherman committed Apr 11, 2013
1 parent e9af7f3 commit a36334c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,39 @@ function using the `configurer` function.
Calling `my-proj.config/config` will work the same as calling
`carica.core/config` except that it will use your config file.

## Middleware

You can change the resulting config map in Carica by adding
middleware. For instance, if you trust the data you are reading and
want to have it evaluated, there is an `eval-config` middleware
provided. If you want the config to be read only once from disk, you
can use the `cache-config` middleware.


```clojure
(ns my-proj.config
(:require [carica.core :refer [configurer
resources]]))

(def config (configurer (resources "proj_config.clj")
[eval-config
cache-config]))
```

In typical middleware fashion, eval-config and cache-config are
functions that take a function as their only argument and return a
function that takes the cfg-map as its only input. For instance, the
cache-config function:

```clojure
(defn cache-config
"Config middleware that will cache the config map so that it is
loaded only once."
[f]
(memoize (fn [cfg-map]
(f cfg-map))))
```

## Testing

Sometimes, during tests, it's handy to be able to override config
Expand Down

0 comments on commit a36334c

Please sign in to comment.