From e5d533156be1ceb6cf5338f8c823933aa68b1cec Mon Sep 17 00:00:00 2001 From: Christian Koch Date: Mon, 20 Sep 2021 15:19:31 -0500 Subject: [PATCH] convert function name to string in remover --- lib/ex_factor/remover.ex | 10 +++++++++- test/ex_factor/remover_test.exs | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/ex_factor/remover.ex b/lib/ex_factor/remover.ex index f4ab270..deef390 100644 --- a/lib/ex_factor/remover.ex +++ b/lib/ex_factor/remover.ex @@ -9,8 +9,11 @@ defmodule ExFactor.Remover do Remove the indicated function and its spec from it's original file. """ def remove(opts) do - source_function = Keyword.fetch!(opts, :source_function) + source_function = opts + |> Keyword.fetch!(:source_function) + |> function_name() source_module = Keyword.get(opts, :source_module) + arity = Keyword.fetch!(opts, :arity) source_path = Keyword.get(opts, :source_path, path(source_module)) dry_run = Keyword.get(opts, :dry_run, false) @@ -66,4 +69,9 @@ defmodule ExFactor.Remover do end defp path(module), do: ExFactor.path(module) + + defp function_name(name) when is_binary(name) do + String.to_atom(name) + end + defp function_name(name), do: name end diff --git a/test/ex_factor/remover_test.exs b/test/ex_factor/remover_test.exs index 3df149c..da9d15c 100644 --- a/test/ex_factor/remover_test.exs +++ b/test/ex_factor/remover_test.exs @@ -42,7 +42,7 @@ defmodule ExFactor.RemoverTest do File.rm("test/support/source_module.ex") end - test "it rewrites the source file and removes code blocks" do + test "it rewrites the source file and removes code blocks when function is a string" do module = """ defmodule ExFactorSampleModule do @somedoc "This is somedoc" @@ -73,7 +73,7 @@ defmodule ExFactor.RemoverTest do opts = [ source_module: ExFactorSampleModule, source_path: "test/tmp/source_module.ex", - source_function: :pub1, + source_function: "pub1", arity: 1 ]