Gno.Changeset.Action (Gno v0.1.0)

Copy Markdown View Source

Defines the action types and shared utilities for Gno.Changeset and Gno.EffectiveChangeset.

The five action types are:

  • :add — insert new statements
  • :update — add statements, overwriting at property level (subject+predicate)
  • :replace — add statements, overwriting at subject level
  • :remove — delete statements
  • :overwrite — only used in Gno.EffectiveChangeset to track implicit removals from :update and :replace actions

Gno.Changeset uses only the first four; Gno.EffectiveChangeset uses all five.

Summary

Functions

Checks if a changeset structure contains any changes.

Extracts a map of actions from the given keywords and returns it with the remaining unprocessed keywords.

Returns a list of the action fields.

Returns true if map contains at least on action field; otherwise returns false.

Types

changes()

@type changes() ::
  Gno.Changeset.t() | Gno.EffectiveChangeset.t() | RDF.Diff.t() | keyword()

t()

@type t() :: :add | :update | :replace | :remove | :overwrite

Functions

empty?(args)

Checks if a changeset structure contains any changes.

extract(args)

Extracts a map of actions from the given keywords and returns it with the remaining unprocessed keywords.

fields()

@spec fields() :: [atom()]

Returns a list of the action fields.

Example

iex> Gno.Changeset.Action.fields()
[:add, :update, :replace, :remove, :overwrite]

is_action_map(map)

(macro)

Returns true if map contains at least on action field; otherwise returns false.

Note, that a single :overwrite doesn't count.

Example

iex> is_action_map(:add)
false

iex> is_action_map(%{foo: []})
false

iex> is_action_map(%{add: []})
true

iex> is_action_map(%{remove: [], replace: []})
true

iex> is_action_map(%{overwrite: []})
false

iex> is_action_map(%Gno.Changeset{})
true