Packages
eventstore
1.0.3
1.4.8
1.4.7
1.4.6
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.2
1.3.1
1.3.0
1.2.3
1.2.2
1.2.1
1.2.0
1.1.0
1.0.3
1.0.2
1.0.1
1.0.0
1.0.0-rc.0
0.17.0
0.16.2
0.16.1
0.16.0
0.15.1
0.15.0
0.14.0
0.14.0-rc.0
0.13.2
0.13.1
0.13.0
0.12.1
0.12.0
0.11.0
0.11.0-rc.0
0.10.1
0.10.0
0.9.0
0.8.1
0.8.0
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.2
0.6.1
0.6.0
0.5.2
0.5.1
0.5.0
0.4.3
0.4.2
0.4.1
0.4.0
0.3.0
0.2.1
0.2.0
0.1.0
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1
Event store using PostgreSQL for persistence.
Current section
Files
Jump to
Current section
Files
lib/mix/event_store.ex
defmodule Mix.EventStore do
@moduledoc """
Conveniences for writing EventStore related Mix tasks.
"""
@doc """
Parses the event store option from the given command line args list.
If no event store option is given, it is retrieved from the application
environment.
"""
@spec parse_event_store([term]) :: [EventStore.t()]
def parse_event_store(args) do
parse_event_store(args, [])
end
defp parse_event_store([key, value | e], acc) when key in ~w(--eventstore -e) do
parse_event_store(e, [Module.concat([value]) | acc])
end
defp parse_event_store([_ | e], acc) do
parse_event_store(e, acc)
end
defp parse_event_store([], []) do
apps =
if apps_paths = Mix.Project.apps_paths() do
Map.keys(apps_paths)
else
[Mix.Project.config()[:app]]
end
apps
|> Enum.flat_map(fn app ->
Application.load(app)
Application.get_env(app, :event_stores, [])
end)
|> Enum.uniq()
|> case do
[] ->
Mix.shell().error("""
warning: could not find event stores in any of the apps: #{inspect(apps)}.
You can avoid this warning by passing the -e flag or by setting the
event stores managed by those applications in your config/config.exs:
config #{inspect(hd(apps))}, event_stores: [...]
""")
[]
event_stores ->
event_stores
end
end
defp parse_event_store([], acc) do
Enum.reverse(acc)
end
@doc """
Ensures the given module is an EventStore.
"""
@spec ensure_event_store(module, list) :: EventStore.t()
def ensure_event_store(event_store, args) do
Mix.Task.run("loadpaths", args)
unless "--no-compile" in args do
Mix.Project.compile(args)
end
case Code.ensure_compiled(event_store) do
{:module, _} ->
if implements?(event_store, EventStore) do
event_store
else
Mix.raise(
"Module #{inspect(event_store)} is not an EventStore. " <>
"Please configure your app accordingly or pass a event store with the -e option."
)
end
{:error, error} ->
Mix.raise(
"Could not load #{inspect(event_store)}, error: #{inspect(error)}. " <>
"Please configure your app accordingly or pass a event store with the -e option."
)
end
end
@doc """
Returns `true` if module implements behaviour.
"""
def implements?(module, behaviour) do
all = Keyword.take(module.__info__(:attributes), [:behaviour])
[behaviour] in Keyword.values(all)
end
end