Skip to content

Commit

Permalink
convert function name to string in remover
Browse files Browse the repository at this point in the history
  • Loading branch information
ckoch-cars committed Sep 20, 2021
1 parent 35f3d3b commit e5d5331
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lib/ex_factor/remover.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions test/ex_factor/remover_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
]

Expand Down

0 comments on commit e5d5331

Please sign in to comment.