Rete.Listener.Collect (Rete v0.2.0)

Copy Markdown View Source

Records every event, newest last.

Use this for tests that assert on what the engine did, instead of on what it holds. It keeps everything, and it grows without bound. Do not leave it attached to a long-lived session.

Summary

Functions

Only the events matching a tag, in order.

The events a session recorded, in the order they happened.

Functions

by_tag(session, tag)

@spec by_tag(Rete.Session.t(), atom()) :: [Rete.Listener.event()]

Only the events matching a tag, in order.

iex> alias Rete.{Listener.Collect, Session}
iex> Session.new([Rete.Doc.Orders])
...> |> Session.with_listener(Collect, [])
...> |> Session.insert([{:customer, 1}, {:order, 1, 250}])
...> |> Session.fire_rules()
...> |> Collect.by_tag(:activation_fired)
...> |> Enum.map(fn {_tag, source, _token, facts} -> {source.rule, facts} end)
[{{Rete.Doc.Orders, :large_order}, [{:flagged, 1, 250}]}]

events(session)

@spec events(Rete.Session.t()) :: [Rete.Listener.event()]

The events a session recorded, in the order they happened.

iex> Rete.Session.new([Rete.Doc.Orders]) |> Rete.Listener.Collect.events()
[]