diff --git a/README.md b/README.md index 332d06e..4f2c456 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,6 @@ Use at your peril, _for now._ - [] find types referenced in the moved specs - [] find private functions references in refactored fn bodies. - [] update test file refs by CLI option - - [] format changes - [] ElixirLS integration for VSCode? - [] Write the module code to rename usages of the refactored function - [] guthub actions, run test suite @@ -34,6 +33,7 @@ Use at your peril, _for now._ - [X] Write a mix task to invoke the Refactorer - [X] dry-run option - [X] CLI output, list files changed and created. + - [X] format changes ## Installation diff --git a/lib/ex_factor.ex b/lib/ex_factor.ex index 93fe7a7..be5144f 100644 --- a/lib/ex_factor.ex +++ b/lib/ex_factor.ex @@ -13,11 +13,23 @@ defmodule ExFactor do alias ExFactor.Remover @doc """ - Call Extractor module emaplce/1 + Call Extractor, Remover, and Formatter modules """ def refactor(opts) do + source_module = Keyword.fetch!(opts, :source_module) + target_module = Keyword.fetch!(opts, :target_module) + + opts = + opts + |> Keyword.put_new(:target_path, path(target_module)) + |> Keyword.put_new(:source_path, path(source_module)) + emplace = Extractor.emplace(opts) remove = Remover.remove(opts) {emplace, remove} end + + def path(module) do + Path.join(["lib", Macro.underscore(module) <> ".ex"]) + end end diff --git a/lib/ex_factor/extractor.ex b/lib/ex_factor/extractor.ex index 34d8b66..f575e08 100644 --- a/lib/ex_factor/extractor.ex +++ b/lib/ex_factor/extractor.ex @@ -67,9 +67,7 @@ defmodule ExFactor.Extractor do end end - defp path(module) do - Path.join(["lib", Macro.underscore(module) <> ".ex"]) - end + defp path(module), do: ExFactor.path(module) defp refactor_message, do: "#refactored function moved with ExFactor" diff --git a/lib/ex_factor/remover.ex b/lib/ex_factor/remover.ex index bdc6fd9..f4ab270 100644 --- a/lib/ex_factor/remover.ex +++ b/lib/ex_factor/remover.ex @@ -65,7 +65,5 @@ defmodule ExFactor.Remover do File.write(path, contents, [:write]) end - defp path(module) do - Path.join(["lib", Macro.underscore(module) <> ".ex"]) - end + defp path(module), do: ExFactor.path(module) end