Skip to content

Commit

Permalink
[#1] internal functions documented
Browse files Browse the repository at this point in the history
  • Loading branch information
shizzard committed Mar 25, 2019
1 parent 8d22e99 commit 9bbfa60
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* [Compile-time options](compile-time-options.md): a set of options that may be used to change `cloak` behavior at compile-time
* [Field types](field-types.md): description of different field types `cloak` supports
* [Runtime errors](runtime-errors.md): runtime errors `cloak` can generate
* [Module interface](module-interface.md): description of all exported functions cloak will generate for you
* [Interface functions](interface-functions.md): description of all exported functions cloak will generate for you
* [Types and specs](types-and-specs.md): exported generated types and function specifications
* [Importers](importers.md): a way to import some fancy-packed data into your datastructure
* [Validators](validators.md): different ways to validate data with user-defined callbacks
Expand Down
43 changes: 43 additions & 0 deletions docs/interface-functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Interface functions

Interface functions are those functions that `cloak` will generate and export from your module.

This section is mostly the [Getting Started](/README.md) guide from the main README file, but contains more details and links to the related documentation.

## `new/1`

`Module:new/1` is the most common way to create an opaque struct. It takes a map with `atom()` or `binary()` keys and `term()` values and returns an opaque record structure, which is obviously a `tuple()`:

Note, that `new/1` totally ignores keys and values that are not presented in record definition, as well as your [private and protected](field-types.md) fields.

If you will declare [datastructure-level importer](importers.md) for your datastructure, `new/1` will accept an argument of any type, not only maps. However, unsure you will return a map from your datastructure-level importer so that `cloak` will be able to perform ordinary initialization steps.

This function also triggers all of [validators](validators.md) declared, both field-level and datastructure-level, in this order.

## `update/2`

`Module:update/2` function may be used to update several fields at a time. It basically acts in the same way as `new/1`, but threats all fields as optional.

While it will also ignore all unknown keys, as well as your [private and protected](field-types.md) fields, it performs per-field merging.

This function will also trigger all [importers](importers.md) and all [validators](validators.md) declared.

## `Getter/1`

`cloak` will generate `Module:Getter/1` function for every [required, optional and protected](field-types.md) field declared.

It is pretty straight-forward and simple returns `?#MODULE{}` record field value.

## `Setter/2`

`cloak` will generate `Module:Getter/1` function for every [required and optional](field-types.md) field declared.

```erlang
7> cloak_example1:two(Opaque, 'CODE').
{cloak_example1,hello,'CODE',generation}
```

## `export/1`

`Module:export/1` returns your data as a map.

0 comments on commit 9bbfa60

Please sign in to comment.