pallet.utils documentation

Utilities used across pallet.

as-string

fn

[arg]

Return the string value of the argument.

base64-md5

fn

[unsafe-id]

Computes the base64 encoding of the md5 of a string

classpath

fn

[]

Return the classpath File's for the current clojure classloader.

classpath-jarfiles

fn

[]

Returns a sequence of JarFile objects for the JAR files on classpath.

classpath-urls

fn

[]

Return the classpath URL's for the current clojure classloader.

compare-and-swap!

fn

[a f & args]

Compare and swap, returning old and new values

compiler-exception

macro

[exception]

Create a compiler exception that wraps a cause and includes source location.

count-by

fn

[key-fn s]

Take a sequence and a key function, and returns a map with the count of each key.

count-values

fn

[s]

Take a sequence, and returns a map with the count of each value.

deep-merge

fn

[& ms]

Recursively merge maps.

dissoc-if-empty

fn

[m key]

Like clojure.core/dissoc, except it only dissoc's if the value at the keyword is nil.

dissoc-keys

fn

[m keys]

Like clojure.core/dissoc, except it takes a vector of keys to remove

file-for-url

fn

[url]

Convert a URL to a File.

find-var-with-require

fn

[sym]
[ns sym]

Find the var for the given namespace and symbol. If the namespace does not exist, then it will be required. (find-var-with-require 'my.ns 'a-symbol) (find-var-with-require 'my.ns/a-symbol)

If the namespace exists, but can not be loaded, and exception is thrown. If the namespace is loaded, but the symbol is not found, then nil is returned.

first-line

fn

[s]

Return the first line of a string.

forward-to-script-lib

macro

[& symbols]

Forward a script to the new script lib

jar-file?

fn

[file]

Returns true if file is a normal file with a .jar or .JAR extension.

local-env

macro

[]

Return clojure's local environment as a map of keyword value pairs.

log-multiline

macro

[level-kw fmt string]

Log a multiline string in multiple log lines

macro-compiler-exception

macro

[exception]

Create a compiler exception that wraps a cause and includes source location.

make-user

fn

[username & {:keys [public-key-path private-key-path passphrase password sudo-password no-sudo], :as options}]

Deprecated: 0.8.0

Creates a User record with the given username and options. Generally used in conjunction with admin-user and pallet.api/with-admin-user, or passed to lift or converge as the named :user argument.

Options: - :public-key-path - :private-key-path - :passphrase - :password - :sudo-password (defaults to :password) - :no-sudo

map-seq

fn

[m]

Given an argument, returns the argument, or nil if passed an empty map.

map-with-keys-as-symbols

fn

[m]

Produce a map that is the same as m, but with all keys are converted to symbols.

maybe-assoc

fn

[m k v]

'Assoc a value in an associative structure, where k is a key and v is the value to assoc. The assoc only occurs if the value is non-nil.

maybe-update-in

fn

[m [& ks] f & args]

'Updates' a value in a nested associative structure, where ks is a sequence of keys and f is a function that will take the old value and any supplied args and return the new value, and returns a new nested structure. If any levels do not exist, hash-maps will be created only if the update function returns a non-nil value. If the update function returns nil, the map is returned unmodified.

middleware

macro

[& forms]

Build a middleware processing pipeline from the specified forms. The result is a middleware.

obfuscate

fn

[pw]

Obfuscate a password, by replacing every character by an asterisk.

pipe

macro

[& forms]

Build a session processing pipeline from the specified forms.

pprint-lines

fn

[s]

Pretty print a multiline string

quoted

fn

[s]

Return the string value of the argument in quotes.

resource-properties

fn

[path]

Given a resource path, load it as a java properties file. Returns nil if resource not found.

slurp-as-byte-array

fn

[file]

Read the given file as a byte array.

tmpdir

fn

[]

Create a temporary directory.

tmpfile

fn

[]
[dir]

Create a temporary file

total-order-merge

fn

[& seqs]

Merge the seqs sequences so that the ordering of the elements in result is the same as the ordering of elements present in each of the specified sequences. Throws an exception if no ordering can be found that satisfies the ordering in all the seqs.

with-temp-file

macro

[[varname content] & body]

Create a block where varname is a temporary File containing content.

with-temporary

macro

[bindings & body]

A block scope allowing multiple bindings to expressions. Each binding will have the member function delete called on it.