@@ -2,7 +2,7 @@ defmodule Console.Plural.Context do
22 import Console
33 alias Console.Deployer
44
5- defstruct [ :configuration , :bundles , :smtp ]
5+ defstruct [ :configuration , :bundles , :smtp , :buckets , :domains ]
66
77 defmodule Smtp do
88 defstruct [ :user , :password , :server , :port , :sender ]
@@ -43,15 +43,21 @@ defmodule Console.Plural.Context do
4343 end
4444 end
4545
46- def merge ( ctx , new_bundles ) do
46+ def merge ( ctx , new_bundles , buckets \\ [ ] , domains \\ [ ] ) do
4747 with { :ok , % { configuration: config , bundles: bundles } = context } <- get ( ) do
4848 updated = DeepMerge . deep_merge ( config , ctx )
49- write ( % { context | configuration: updated , bundles: merge_bundles ( new_bundles , bundles ) } )
49+ % { context | configuration: updated , bundles: merge_list ( new_bundles , bundles ) }
50+ |> add_meta ( buckets , domains )
51+ |> write ( )
5052 end
5153 end
5254
53- defp merge_bundles ( [ _ | _ ] = new , bundles ) , do: Enum . uniq ( new ++ bundles )
54- defp merge_bundles ( b , bundles ) , do: merge_bundles ( [ b ] , bundles )
55+ defp add_meta ( % __MODULE__ { buckets: buckets , domains: domains } = ctx , new_buckets , new_domains ) do
56+ % { ctx | buckets: merge_list ( buckets || [ ] , new_buckets || [ ] ) , domains: merge_list ( domains || [ ] , new_domains || [ ] ) }
57+ end
58+
59+ defp merge_list ( new , bundles ) when is_list ( new ) , do: Enum . uniq ( new ++ bundles )
60+ defp merge_list ( b , bundles ) , do: merge_list ( [ b ] , bundles )
5561
5662 def write ( % __MODULE__ { bundles: bundles , configuration: conf , smtp: smtp } = context ) do
5763 sanitized = % {
0 commit comments