mix mailglass.gen.inbound_route (Mailglass v1.4.4)

Copy Markdown View Source

Appends a route/2 clause to an existing MailglassInbound.Router module.

The edit is idempotent: running the task twice for the same mailbox is a no-op. The route is appended as the last statement inside the router's do-block.

Examples

mix mailglass.gen.inbound_route support@example.com MyApp.SupportMailbox
mix mailglass.gen.inbound_route support@example.com MyApp.SupportMailbox --router MyApp.InboundRouter

Positional arguments

  • pattern - the envelope recipient to match (becomes recipient: "<pattern>").
  • mailbox - the mailbox module that handles the matched message.

Options

  • --router - the router module to edit. Defaults to <App>.InboundRouter.
  • --recipient - override the recipient matcher (defaults to pattern).
  • --subject - add a subject: matcher to the generated route.

--dry-run is supported as the framework-provided global switch (it is not in this task's option schema); it previews the diff and writes nothing.

Summary

Functions

Idempotently appends a route/2 for mailbox to router's do-block.

Returns true when the router's do-block already declares a route/2 whose first argument is mailbox.

Resolves the router module to edit, honoring an explicit --router value and otherwise defaulting to <App>.InboundRouter.

Functions

add_route(igniter, router, mailbox, opts)

@spec add_route(Igniter.t(), module(), module(), keyword()) :: Igniter.t()

Idempotently appends a route/2 for mailbox to router's do-block.

Reused by mix mailglass.gen.mailbox so the route-stub insertion shares the exact same dup-scan + add-route logic. When the router module is not found in the project, an actionable notice is emitted (no module is auto-created).

opts accepts:

  • :recipient - the recipient matcher string (required for a useful route).
  • :subject - an optional subject matcher string.

route_already_present?(zipper, mailbox)

@spec route_already_present?(Sourceror.Zipper.t(), module()) :: boolean()

Returns true when the router's do-block already declares a route/2 whose first argument is mailbox.

The zipper must be positioned at the router's do-block (as provided by Igniter.Project.Module.find_and_update_module/3). Idempotency hinges on argument_equals?/3 resolving the {:__aliases__, ...} mailbox AST against the module atom.

router_module(igniter, router_arg)

@spec router_module(Igniter.t(), String.t() | nil) :: module()

Resolves the router module to edit, honoring an explicit --router value and otherwise defaulting to <App>.InboundRouter.