@@ -97,16 +97,7 @@ defmodule Igniter.Project.Config do
9797 |> Igniter . include_or_create_file ( config_file_path , file_contents )
9898 |> ensure_default_configs_exist ( file_path )
9999 |> Igniter . update_elixir_file ( config_file_path , fn zipper ->
100- case Zipper . find ( zipper , fn
101- { :import , _ , [ Config ] } ->
102- true
103-
104- { :import , _ , [ { :__aliases__ , _ , [ :Config ] } ] } ->
105- true
106-
107- _ ->
108- false
109- end ) do
100+ case find_config ( zipper ) do
110101 nil ->
111102 { :warning ,
112103 bad_config_message (
@@ -272,16 +263,7 @@ defmodule Igniter.Project.Config do
272263 |> ensure_default_configs_exist ( file_name )
273264 |> Igniter . include_or_create_file ( file_path , file_contents )
274265 |> Igniter . update_elixir_file ( file_path , fn zipper ->
275- case Zipper . find ( zipper , fn
276- { :import , _ , [ Config ] } ->
277- true
278-
279- { :import , _ , [ { :__aliases__ , _ , [ :Config ] } ] } ->
280- true
281-
282- _ ->
283- false
284- end ) do
266+ case find_config ( zipper ) do
285267 nil ->
286268 { :warning , bad_config_message ( app_name , file_path , config_path , value , opts ) }
287269
@@ -294,6 +276,44 @@ defmodule Igniter.Project.Config do
294276 end )
295277 end
296278
279+ @ doc """
280+ Removes an applications config completely.
281+ """
282+ @ spec remove_application_configuration ( Igniter . t ( ) , Path . t ( ) , atom ( ) ) :: Igniter . t ( )
283+ def remove_application_configuration ( igniter , file_name , app_name ) do
284+ file_path = config_file_path ( igniter , file_name )
285+
286+ Igniter . update_elixir_file (
287+ igniter ,
288+ file_path ,
289+ fn zipper ->
290+ case find_config ( zipper ) do
291+ nil -> igniter
292+ _ -> recursively_remove_configurations ( zipper , app_name )
293+ end
294+ end ,
295+ required?: false
296+ )
297+ end
298+
299+ defp recursively_remove_configurations ( zipper , app_name ) do
300+ case Igniter.Code.Function . move_to_function_call_in_current_scope (
301+ zipper ,
302+ :config ,
303+ [ 2 , 3 ] ,
304+ & Igniter.Code.Function . argument_equals? ( & 1 , 0 , app_name )
305+ ) do
306+ :error ->
307+ zipper
308+
309+ { :ok , zipper } ->
310+ zipper
311+ |> Zipper . remove ( )
312+ |> Zipper . top ( )
313+ |> recursively_remove_configurations ( app_name )
314+ end
315+ end
316+
297317 defp config_file_path ( igniter , file_name ) do
298318 case igniter |> Igniter.Project.Application . config_path ( ) |> Path . split ( ) do
299319 [ path ] -> [ path ]
@@ -734,4 +754,17 @@ defmodule Igniter.Project.Config do
734754 defp simple_atom ( value ) do
735755 is_atom ( value ) and Regex . match? ( ~r/ ^[a-z_][a-zA-Z0-9_?!]*$/ , to_string ( value ) )
736756 end
757+
758+ defp find_config ( zipper ) do
759+ Zipper . find ( zipper , fn
760+ { :import , _ , [ Config ] } ->
761+ true
762+
763+ { :import , _ , [ { :__aliases__ , _ , [ :Config ] } ] } ->
764+ true
765+
766+ _ ->
767+ false
768+ end )
769+ end
737770end
0 commit comments