Enact.Delegates (Enact v0.1.0)

Copy Markdown View Source

Opt-in helper that generates context one-liners for Enact.run/3, Enact.dry_run/3, Enact.subject/3, and Enact.authorized/3.

Phoenix contexts remain the application API; this only writes the forwarding functions hosts otherwise type by hand. It is not an action-definition DSL — actions stay ordinary modules, and handwritten delegates remain valid.

defmodule MyApp.Contacts do
  alias MyApp.Contacts.Actions.{CreateContact, UpdateContact}

  use Enact.Delegates, actions: [CreateContact, UpdateContact]

  # reads and load_subject fetchers stay here
end

For each action MyApp.Contacts.Actions.CreateContact, this defines:

def create_contact(params, opts),
  do: Enact.run(CreateContact, params, opts)

def create_contact_dry_run(params, opts),
  do: Enact.dry_run(CreateContact, params, opts)

def create_contact_subject(params, opts),
  do: Enact.subject(CreateContact, params, opts)

def create_contact_authorized(params, opts),
  do: Enact.authorized(CreateContact, params, opts)

Names come from the last segment of the module, underscored via Macro.underscore/1. All four wrappers are generated for every listed action. Bodies only forward — no param reshaping, no persistable fields stamped in.

If a host wants a different public name or a non-forwarding body, omit that module from the list and write the function by hand.