Liking cljdoc? Tell your friends :D

keypin.core

Public API for the core functionality.

Public API for the core functionality.
raw docstring

defkeycljmacro

(defkey the-sym arg-vec & more)

Define one or more keys as defn vars using argument vectors, which could be invoked as (keydef store) to fetch the value of the key. Every argument vector must have one of the following arities:

[key]
[key options]
[key validator description]
[key validator description options]

Options

KwargDescription
:predValidator function (fn [value]) -> boolean - default fn just returns true
:descDescription string for the config - default: "No description"
:lookupFunction to look the key up (details below) - default: lookup-key - ordinary key look up
:parserThe value parser fn (fn [key raw-value]) -> parsed-value, e.g. keypin.util/str->long
:defaultDefault value when key is not found (subject to validator, unspecified => no default value)
:syspropSystem property name that can override the config value (before parsing)
:envvarEnvironment variable that can override the config value and system property (before parsing)
:sourceSource or container (of reference type, e.g. atom/agent/promise etc.) of key/value pairs
:pre-xformMiddleware function (fn [option-map]) -> option-map used before key definition is created
:post-xformMiddleware function (fn [keypin.type.KeyAttributes]) -> keypin.type.KeyAttributes

The validator is a predicate (fn [parsed-value]) -> boolean that returns true for valid values, false otherwise.

First argument to defkey can optionally be a base option-map for all argument vectors.

Examples

(defkey
  ip   [:ip-address]
  port [:port #(< 1023 % 65535) "Server port" {:parser keypin.util/str->int :default 3000}])

(port {:port "3009"})  ; returns 3009
(port {})              ; returns 3000

(defkey
  {:lookup lookup-key}
  ip   ["server.ip.address"]
  port ["server.port" #(< 1023 % 65535) "Server port" {:parser keypin.util/str->int :default 3000}])

See: make-key

Define one or more keys as `defn` vars using argument vectors, which could be invoked as `(keydef store)` to
fetch the value of the key. Every argument vector must have one of the following arities:

```
[key]
[key options]
[key validator description]
[key validator description options]
```

### Options

| Kwarg       | Description |
|-------------|-------------|
|`:pred`      |Validator function `(fn [value]) -> boolean` - default fn just returns `true`  |
|`:desc`      |Description string for the config - default: `"No description"`              |
|`:lookup`    |Function to look the key up (details below) - default: [[lookup-key]] - ordinary key look up |
|`:parser`    |The value parser fn `(fn [key raw-value]) -> parsed-value`, e.g. [[keypin.util/str->long]]   |
|`:default`   |Default value when key is not found (subject to validator, unspecified => no default value)  |
|`:sysprop`   |System property name that can override the config value (before parsing)                     |
|`:envvar`    |Environment variable that can override the config value and system property (before parsing) |
|`:source`    |Source or container (of reference type, e.g. atom/agent/promise etc.) of key/value pairs     |
|`:pre-xform` |Middleware function `(fn [option-map]) -> option-map` used before key definition is created  |
|`:post-xform`|Middleware function `(fn [keypin.type.KeyAttributes]) -> keypin.type.KeyAttributes`          |

The `validator` is a predicate `(fn [parsed-value]) -> boolean` that returns `true` for valid values,
`false` otherwise.

First argument to `defkey` can optionally be a base option-map for all argument vectors.

### Examples

```
(defkey
  ip   [:ip-address]
  port [:port #(< 1023 % 65535) "Server port" {:parser keypin.util/str->int :default 3000}])

(port {:port "3009"})  ; returns 3009
(port {})              ; returns 3000

(defkey
  {:lookup lookup-key}
  ip   ["server.ip.address"]
  port ["server.port" #(< 1023 % 65535) "Server port" {:parser keypin.util/str->int :default 3000}])
```

See: [[make-key]]
sourceraw docstring

edn-file-ioclj

Reader/writer for EDN files.

Reader/writer for EDN files.
sourceraw docstring

letvalcljmacro

(letval bindings & body)

Like let, except in which the left hand side is a destructuring map, right hand side is the argument to key finder. Beside symbols, the destructuring map optionally supports :defs (symbols bound to key finders) and :as keys.

Example

(letval [{:defs [foo bar] ; foo, bar are key finders
          baz baz-key     ; baz-key is a key finder
          :as m} {:foo 10 :bar 20 :baz 30}]
  ;; foo, bar and baz are now bound to values looked up in the map
  ...)
Like `let`, except in which the left hand side is a destructuring map, right hand side is the argument to key finder.
Beside symbols, the destructuring map optionally supports `:defs` (symbols bound to key finders) and `:as` keys.

### Example

```
(letval [{:defs [foo bar] ; foo, bar are key finders
          baz baz-key     ; baz-key is a key finder
          :as m} {:foo 10 :bar 20 :baz 30}]
  ;; foo, bar and baz are now bound to values looked up in the map
  ...)
```
sourceraw docstring

lookup-keyclj

(lookup-key the-map
            the-key
            validator
            description
            value-parser
            default-value?
            default-value
            not-found)

Look up a key in an associative data structure - a map or something that implements clojure.lang.Associative.

Look up a key in an associative data structure - a map or something that implements `clojure.lang.Associative`.
sourceraw docstring

lookup-keypathclj

(lookup-keypath the-map
                ks
                validator
                description
                value-parser
                default-value?
                default-value
                not-found)

Look up a key path in an associative data structure - a map or something that implements clojure.lang.Associative.

Look up a key path in an associative data structure - a map or something that implements `clojure.lang.Associative`.
sourceraw docstring

make-keyclj

(make-key {:keys [the-key pred desc lookup parser default sysprop envvar source]
           :or {pred i/return-true
                desc "No description"
                lookup lookup-key
                parser i/identity-parser}
           :as options})

Create a key that can be looked up in a config store (keypin.type/IStore, java.util.Map, java.util.Properties or map/vector) instance.

Options

KwargDescription
:the-key(Required) Key to be used for looking up value
:predValidator function (fn [value]) -> boolean - default fn just returns true
:descDescription string for the config - default: "No description"
:lookupFunction to look the key up (details below) - default: lookup-key - ordinary key look up
:parserThe value parser fn (fn [key raw-value]) -> parsed-value, e.g. keypin.util/str->long
:defaultDefault value when key is not found (subject to validator, unspecified => no default value)
:syspropSystem property name that can override the config value (before parsing)
:envvarEnvironment variable that can override the config value and system property (before parsing)
:sourceSource or container (of reference type, e.g. atom/agent/promise etc.) of key/value pairs

Lookup function

(fn [store
     key
     validator
     description
     value-parser
     default-value?
     default-value
     not-found-handler]) -> value

;; validator is a predicate function: (fn [parsed-value]) -> boolean
;; not-found-handler is (fn [not-found-message]), called when the store does not have the key

See: lookup-key, lookup-keypath

Create a key that can be looked up in a config store (`keypin.type/IStore`, `java.util.Map`, `java.util.Properties`
or map/vector) instance.

### Options

| Kwarg    | Description                 |
|----------|-----------------------------|
|`:the-key`|(Required) Key to be used for looking up value                                |
|`:pred`   |Validator function `(fn [value]) -> boolean` - default fn just returns true   |
|`:desc`   |Description string for the config - default: `"No description"`             |
|`:lookup` |Function to look the key up (details below) - default: [[lookup-key]] - ordinary key look up |
|`:parser` |The value parser fn `(fn [key raw-value]) -> parsed-value`, e.g. [[keypin.util/str->long]]   |
|`:default`|Default value when key is not found (subject to validator, unspecified => no default value)  |
|`:sysprop`|System property name that can override the config value (before parsing)                     |
|`:envvar` |Environment variable that can override the config value and system property (before parsing) |
|`:source` |Source or container (of reference type, e.g. atom/agent/promise etc.) of key/value pairs     |

### Lookup function

```
(fn [store
     key
     validator
     description
     value-parser
     default-value?
     default-value
     not-found-handler]) -> value

;; validator is a predicate function: (fn [parsed-value]) -> boolean
;; not-found-handler is (fn [not-found-message]), called when the store does not have the key
```

See: [[lookup-key]], [[lookup-keypath]]
sourceraw docstring

property-file-ioclj

Reader/writer for properties files.

Reader/writer for properties files.
sourceraw docstring

read-configclj

(read-config config-filenames)
(read-config config-filenames
             {:keys [parent-key logger config-readers media-readers realize?]
              :or {parent-key "parent.filenames"
                   logger u/default-logger
                   config-readers [property-file-io edn-file-io]
                   realize? true}
              :as options})

Read config file(s) returning a java.util.Map instance.

Options

KwargTypeDescriptionDefault
:parent-keystringkey to identify the parent config filenames"parent.filenames"
:loggerobjectinstance of keypin.Loggerprints to *err*
:config-readerslist/veccollection of keypin.ConfigIO instancesfor .properties, .edn files
:media-readerslist/veccollection of keypin.MediaReader instancesfor filesystem and classpath
:realize?booleanwhether realize template variables in stringtrue
Read config file(s) returning a `java.util.Map` instance.

### Options

| Kwarg           | Type     | Description                                  | Default                         |
|-----------------|----------|----------------------------------------------|---------------------------------|
|`:parent-key`    | string   | key to identify the parent config filenames  | `"parent.filenames"`          |
|`:logger`        | object   | instance of `keypin.Logger`                  | prints to `*err*`               |
|`:config-readers`| list/vec | collection of `keypin.ConfigIO` instances    | for `.properties`, `.edn` files |
|`:media-readers` | list/vec | collection of `keypin.MediaReader` instances | for filesystem and classpath    |
|`:realize?`      | boolean  | whether realize template variables in string | `true`                          |
sourceraw docstring

realize-configclj

(realize-config config)
(realize-config config
                {:keys [logger config-mapper]
                 :or {logger u/default-logger config-mapper Mapper/DEFAULT}
                 :as options})

Realize config by applying variable substitution, if any.

Options

KwargTypeDescriptionDefault
:loggerobjectinstance of keypin.Loggerprints to *err*
:config-mapperobjectinstance of keypin.Mapperkeypin.Mapper/DEFAULT
Realize config by applying variable substitution, if any.

### Options

| Kwarg          | Type   | Description                 | Default                 |
|----------------|--------|-----------------------------|-------------------------|
|`:logger`       | object | instance of `keypin.Logger` | prints to `*err*`       |
|`:config-mapper`| object | instance of `keypin.Mapper` | `keypin.Mapper/DEFAULT` |
sourceraw docstring

write-configclj

(write-config config-filename config)
(write-config config-filename
              config
              {:keys [logger config-writers escape?]
               :or {logger u/default-logger
                    config-writers [property-file-io edn-file-io]
                    escape? true}
               :as options})

Write config to a specified file.

Options

KwargTypeDescriptionDefault
:loggerobjectinstance of keypin.Loggerprints to *err*
:config-writerslist/veccollection of keypin.ConfigIO instancesfor .properties, .edn files
:escape?booleanwhether escape values when writingtrue
Write config to a specified file.

### Options

| Kwarg           | Type     | Description                               | Default                         |
|-----------------|----------|-------------------------------------------|---------------------------------|
|`:logger`        | object   | instance of `keypin.Logger`               | prints to `*err*`               |
|`:config-writers`| list/vec | collection of `keypin.ConfigIO` instances | for `.properties`, `.edn` files |
|`:escape?`       | boolean  | whether escape values when writing        | `true`                          |
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close