AttrEngine.Helpers.CustomAttributes (attr_engine v0.3.0)

Copy Markdown View Source

Helper functions for managing custom attributes stored in JSONB fields.

For entities that embed attribute data directly (rather than via ASD), this module provides get/put/validate helpers.

The JSONB structure is:

%{
  "attribute_set_id_1" => %{"field_a" => "value1", "field_b" => 42},
  "attribute_set_id_2" => %{"field_c" => true}
}

Top-level keys are attribute set IDs, values are maps of handle → value.

Summary

Functions

Get a single custom attribute value.

Get all custom attributes for a given attribute set.

Set a single custom attribute value. Returns updated entity.

Set all custom attributes for a given attribute set.

Functions

get(entity, attribute_set_id, handle)

@spec get(map() | struct(), String.t(), String.t()) :: any()

Get a single custom attribute value.

get_set(entity, attribute_set_id)

@spec get_set(map() | struct(), String.t()) :: map()

Get all custom attributes for a given attribute set.

put(entity, attribute_set_id, handle, value)

@spec put(struct(), String.t(), String.t(), any()) :: struct()

Set a single custom attribute value. Returns updated entity.

put_set(entity, attribute_set_id, set_data)

@spec put_set(struct(), String.t(), map()) :: struct()

Set all custom attributes for a given attribute set.