summaryrefslogtreecommitdiff
path: root/src/rebar_config.erl
diff options
context:
space:
mode:
authorDave Smith <dizzyd@dizzyd.com>2009-12-12 07:34:29 -0700
committerDave Smith <dizzyd@dizzyd.com>2009-12-12 07:34:29 -0700
commit3990f0a0766e5e508e319e73139df93cc4c3bde4 (patch)
tree6b5599ac7cf44280fba6f1ae9c76b5594232cdcc /src/rebar_config.erl
parent726f8e6946f8ee36aca80b71dca10a5506445c35 (diff)
Refactor of core logic to provide better control over recursion and code path mgmt
Diffstat (limited to 'src/rebar_config.erl')
-rw-r--r--src/rebar_config.erl55
1 files changed, 18 insertions, 37 deletions
diff --git a/src/rebar_config.erl b/src/rebar_config.erl
index 199461c..f9813c2 100644
--- a/src/rebar_config.erl
+++ b/src/rebar_config.erl
@@ -24,10 +24,9 @@
%% -------------------------------------------------------------------
-module(rebar_config).
--export([new/1,
- get_modules/2,
- get_list/3,
- get/3,
+-export([new/0, new/1,
+ get/3, get_list/3,
+ delete/2,
set_global/2, get_global/2]).
-include("rebar.hrl").
@@ -40,45 +39,34 @@
%% Public API
%% ===================================================================
-new(Dir) ->
- {ok, DefaultConfig} = application:get_env(rebar, default_config),
- BaseDict = orddict:from_list(DefaultConfig),
+new() ->
+ #config { dir = rebar_utils:get_cwd(),
+ opts = []}.
+new(ParentConfig) ->
%% Load terms from rebar.config, if it exists
+ Dir = rebar_utils:get_cwd(),
ConfigFile = filename:join([Dir, "rebar.config"]),
case file:consult(ConfigFile) of
{ok, Terms} ->
- Dict = merge_terms(Terms, BaseDict);
+ Opts = Terms ++ ParentConfig#config.opts;
{error, enoent} ->
- Dict = BaseDict;
+ Opts = ParentConfig#config.opts;
Other ->
+ Opts = undefined, % Keep erlc happy
?WARN("Failed to load ~s: ~p\n", [ConfigFile, Other]),
- ?FAIL,
- Dict = BaseDict
+ ?FAIL
end,
- #config { dir = Dir, opts = Dict }.
-
-
-get_modules(Config, app) ->
- get_list(Config, app_modules, []);
-get_modules(Config, rel) ->
- get_list(Config, rel_modules, []).
+ #config { dir = Dir, opts = Opts }.
get_list(Config, Key, Default) ->
- case orddict:find(Key, Config#config.opts) of
- error ->
- Default;
- {ok, List} ->
- List
- end.
+ get(Config, Key, Default).
get(Config, Key, Default) ->
- case orddict:find(Key, Config#config.opts) of
- error ->
- Default;
- {ok, Value} ->
- Value
- end.
+ proplists:get_value(Key, Config#config.opts, Default).
+
+delete(Config, Key) ->
+ Config#config { opts = proplists:delete(Key, Config#config.opts) }.
set_global(Key, Value) ->
application:set_env(rebar_global, Key, Value).
@@ -95,10 +83,3 @@ get_global(Key, Default) ->
%% ===================================================================
%% Internal functions
%% ===================================================================
-
-merge_terms([], Dict) ->
- Dict;
-merge_terms([{Key, Value} | Rest], Dict) ->
- merge_terms(Rest, orddict:store(Key, Value, Dict));
-merge_terms([_ | Rest], Dict) ->
- merge_terms(Rest, Dict).