Altex.Entity (Altex.Repo v0.1.2) View Source
An Entity is a wrapper around any data that implements the
Persistable protocol.
It's aim is to handle and track changes. (Yes, think about
Ecto.Changeset but different)
An Entity-implementatoin must implement the Persistable protocol,
thus Entity can call init, get, and validate.
Link to this section Summary
Functions
As force_init but skipping validation
Get the value of key from data of the entity when the entity implements the
get-function of the Persistable protocol.
Examples:
iex> entity = Entity.init(1)
...> %Entity{data: 1, uuid: _uuid} = entity
iex> entity = Entity.init(1.4)
...> %Entity{data: 1.4, uuid: _uuid} = entity
iex> entity = Entity.init(:something)
...> %Entity{data: :something, uuid: _uuid } = entity
iex> entity = Entity.init(~w/hello world/)
...> %Entity{data: ["hello", "world"], uuid: _uuid } = entity
iex> entity = Entity.init({:foo, :bar})
...> %Entity{data: {:foo, :bar}, uuid: _uuid } = entityCheck entity and set errors: [] if any.
Link to this section Types
Specs
Link to this section Functions
As force_init but skipping validation
Specs
Get the value of key from data of the entity when the entity implements the
get-function of the Persistable protocol.
Example
iex> e = Entity.init(%{foo: :bar})
...> Entity.get(e, :foo)
:bar
iex> e = Entity.init(%{ 1 => :foo, 2 => :bar})
...> Entity.get(e, 2)
:bar
Examples:
iex> entity = Entity.init(1)
...> %Entity{data: 1, uuid: _uuid} = entity
iex> entity = Entity.init(1.4)
...> %Entity{data: 1.4, uuid: _uuid} = entity
iex> entity = Entity.init(:something)
...> %Entity{data: :something, uuid: _uuid } = entity
iex> entity = Entity.init(~w/hello world/)
...> %Entity{data: ["hello", "world"], uuid: _uuid } = entity
iex> entity = Entity.init({:foo, :bar})
...> %Entity{data: {:foo, :bar}, uuid: _uuid } = entity
Specs
Check entity and set errors: [] if any.