liberator-mixin.core
Functions for defining liberator mixins: partial liberator resource definitions that can be composed together to build up a liberator resource with canned functionality.
The most important function in this namespace is build-resource which accepts a sequence of liberator mixins (or resource definition maps) and produces a liberator resource.
build-resource
(build-resource & ms-or-seqs)
Builds a liberator resource from the specified resource definitions, specified as either maps or sequences of maps.
This function represents the core of the mixin functionality in that each mixin produces either a map or a sequence of maps representing partial resource definitions.
The resource definitions are merged together using merge-resource-definitions. See the documentation there for specific details of the merge process used.
is-action?
(is-action? k)
Returns true
if k
, a keyword, represents a liberator action, false
otherwise.
is-configuration?
(is-configuration? k)
Return true
if k
, a keyword, represents a liberator configuration parameter, false
otherwise.
is-decision?
(is-decision? k)
Returns true
if k
, a keyword, represents a liberator decision, false
otherwise.
is-handler?
(is-handler? k)
Returns true
if k
, a keyword, represents a liberator handler, false
otherwise.
merge-actions
(merge-actions left right)
Merges together two liberator actions, left
and right
.
The resulting action will execute both actions in the order left
first, then right
, such that the right
action will see any context updates made by the left
. The result will be that of the right
action.
merge-configurations
(merge-configurations left right)
Merges together two liberator configuration parameters, left
and right
.
The resulting configuration parameter will be deduced as follows:
- If
right
includes:replace
in its metadata, the result will beright
. - If
left
results in a list, the result will be a list containing all elements fromright
followed by all elements fromleft
, such thatright
takes precedence. - If
left
results in a vector, the result will be a vector containing all elements fromright
followed by all elements fromleft
, such thatright
takes precedence. - If
left
results in a set, the result will be a set containing the union ofleft
andright
. - Otherwise, the result will be
right
.
Both left
and right
can also be functions taking context
returning in line with the above types.
merge-decisions
(merge-decisions left right comparator)
Merges together two liberator decisions, left
and right
.
Decisions can return various different shapes of result:
- boolean, i.e.,
true
orfalse
- truthy, e.g.,
{:foo :bar}
which representstrue
and is used to update the context - vector of boolean and context update, e.g.,
[true, {:foo :bar}]
The resulting decision merges these return values in such a way that both the boolean result of the decision is retained and all context updates are made correctly.
The decisions are applied in the order left
first, then right
, such that the right
decision will see any context updates made by the left
.
merge-handlers
(merge-handlers left right)
Merges together two liberator handlers, left
and right
.
Currently, the left
handler is discarded and the right
is used in its place. In future, this may be improved such that some aspect of the left
handler is retained.
merge-resource-definitions
(merge-resource-definitions & maps)
Merges together multiple liberator resource definitions, specified as maps.
For the mechanism employed:
- for liberator decisions, see merge-decisions,
- for liberator actions, see merge-actions,
- for liberator handlers, see merge-handlers,
- for liberator configuration, see merge-configurations.
Any other map keys that do not correspond to the above liberator definition types will be retained in the resulting resource definition. If the same non-liberator definition map key is specified more than once, the rightmost definition takes precedence.