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

feat: add swoosh module #149

Merged
merged 4 commits into from
Nov 12, 2024
Merged
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
24 changes: 24 additions & 0 deletions lib/igniter/libs/swoosh.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
defmodule Igniter.Libs.Swoosh do
@moduledoc "Codemods & utilities for working with Swoosh"

@doc "Lists all project modules that call `use Swoosh.Mailer`."
@spec list_mailers(Igniter.t()) :: {Igniter.t(), [module()]}
def list_mailers(igniter) do
Igniter.Project.Module.find_all_matching_modules(igniter, fn _mod, zipper ->
move_to_mailer_use(zipper) != :error
end)
end

@doc "Moves to the use statement in a module that matches `use Swoosh.Mailer`"
@spec move_to_mailer_use(Sourceror.Zipper.t()) ::
:error | {:ok, Sourceror.Zipper.t()}
def move_to_mailer_use(zipper) do
Igniter.Code.Function.move_to_function_call(zipper, :use, 2, fn zipper ->
Igniter.Code.Function.argument_equals?(
zipper,
0,
Swoosh.Mailer
)
end)
end
end
Loading