aboutsummaryrefslogtreecommitdiffstats
path: root/lib/lkn/core/entity.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lkn/core/entity.ex')
-rw-r--r--lib/lkn/core/entity.ex14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/lkn/core/entity.ex b/lib/lkn/core/entity.ex
index 7e7a2a6..715970a 100644
--- a/lib/lkn/core/entity.ex
+++ b/lib/lkn/core/entity.ex
@@ -72,6 +72,7 @@ defmodule Lkn.Core.Entity do
`Lkn.Core.Puppet` or a `Lkn.Core.Map`.
"""
@type k :: Lkn.Core.Map.k | Lkn.Core.Puppet.k
+ @type digest :: term
@typedoc """
The third argument of the `start_link/3` function which is passed to
@@ -86,6 +87,8 @@ defmodule Lkn.Core.Entity do
"""
@callback init_properties(init_args) :: %{prop => value}
+ @callback digest(entity :: %{prop => value}) :: digest
+
defmacro __using__(components: comps) do
quote location: :keep do
use Supervisor
@@ -94,6 +97,7 @@ defmodule Lkn.Core.Entity do
def init(key: entity_key, args: args) do
props = init_properties(args)
+ props = Map.put(props, :make_digest, & __MODULE__.digest(&1))
sys = Enum.map(unquote(comps), &(&1.specs().system()))
@@ -109,6 +113,16 @@ defmodule Lkn.Core.Entity do
end
@doc """
+ Compute a digest which hopefully describes the entity
+ """
+ @spec digest(entity_key :: k) :: digest
+ def digest(entity_key) do
+ Option.some(di) = Lkn.Core.Entity.read(entity_key, :make_digest)
+
+ Lkn.Core.Properties.compute(entity_key, di)
+ end
+
+ @doc """
Starts an Entity process linked to the current process.
"""
@spec start_link(module, k, init_args) :: Supervisor.on_start