mirror of
https://github.com/correl/rebar.git
synced 2024-12-18 11:06:20 +00:00
Use dict() instead of proplist() for shared env
This commit is contained in:
parent
d726e598b5
commit
b2fdce8879
1 changed files with 6 additions and 9 deletions
|
@ -38,10 +38,7 @@
|
||||||
|
|
||||||
-record(config, { dir :: file:filename(),
|
-record(config, { dir :: file:filename(),
|
||||||
opts = [] :: list(),
|
opts = [] :: list(),
|
||||||
envs = [] :: list({module(), env()}) }).
|
envs = new_env() :: dict() }).
|
||||||
|
|
||||||
-type env() :: [env_var()].
|
|
||||||
-type env_var() :: {string(), string()}.
|
|
||||||
|
|
||||||
%% Types that can be used from other modules -- alphabetically ordered.
|
%% Types that can be used from other modules -- alphabetically ordered.
|
||||||
-export_type([config/0]).
|
-export_type([config/0]).
|
||||||
|
@ -149,14 +146,11 @@ consult_file(File) ->
|
||||||
|
|
||||||
set_env(Config, Mod, Env) ->
|
set_env(Config, Mod, Env) ->
|
||||||
OldEnvs = Config#config.envs,
|
OldEnvs = Config#config.envs,
|
||||||
NewEnvs = case lists:keymember(Mod, 1, OldEnvs) of
|
NewEnvs = dict:store(Mod, Env, OldEnvs),
|
||||||
true -> lists:keyreplace(Mod, 1, OldEnvs, {Mod, Env});
|
|
||||||
false -> [{Mod,Env}|OldEnvs]
|
|
||||||
end,
|
|
||||||
Config#config{envs=NewEnvs}.
|
Config#config{envs=NewEnvs}.
|
||||||
|
|
||||||
get_env(Config, Mod) ->
|
get_env(Config, Mod) ->
|
||||||
proplists:get_value(Mod, Config#config.envs, []).
|
dict:fetch(Mod, Config#config.envs).
|
||||||
|
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
|
@ -193,3 +187,6 @@ local_opts([local | _Rest], Acc) ->
|
||||||
lists:reverse(Acc);
|
lists:reverse(Acc);
|
||||||
local_opts([Item | Rest], Acc) ->
|
local_opts([Item | Rest], Acc) ->
|
||||||
local_opts(Rest, [Item | Acc]).
|
local_opts(Rest, [Item | Acc]).
|
||||||
|
|
||||||
|
new_env() ->
|
||||||
|
dict:new().
|
||||||
|
|
Loading…
Reference in a new issue