Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework macro to avoid compile-time dependency on given application #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lib/projections/ecto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,24 @@ defmodule Commanded.Projections.Ecto do
schema_prefix =
opts[:schema_prefix] || Application.get_env(:commanded_ecto_projections, :schema_prefix)

repo = opts[:repo]
timeout = opts[:timeout] || :infinity

# Pass through any other configuration to the event handler
handler_opts = Keyword.drop(opts, [:repo, :schema_prefix, :timeout])

quote location: :keep do
@behaviour Commanded.Projections.Ecto

@opts unquote(opts)
@repo @opts[:repo] || Application.compile_env(:commanded_ecto_projections, :repo) ||
@repo unquote(repo) || Application.compile_env(:commanded_ecto_projections, :repo) ||
raise("Commanded Ecto projections expects :repo to be configured in environment")
@timeout @opts[:timeout] || :infinity

# Pass through any other configuration to the event handler
@handler_opts Keyword.drop(@opts, [:repo, :schema_prefix, :timeout])
@timeout unquote(timeout)

unquote(__include_schema_prefix__(schema_prefix))
unquote(__include_projection_version_schema__())

use Ecto.Schema
use Commanded.Event.Handler, @handler_opts
use Commanded.Event.Handler, unquote(handler_opts)

import Ecto.Changeset
import Ecto.Query
Expand Down
Loading