25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +01:00

Remove duplicated code

This commit is contained in:
Evgeniy Khramtsov 2015-04-29 14:51:45 +03:00
parent 6987e85602
commit 60fe008268

View File

@ -209,6 +209,13 @@ get_opt_host(Host, Opts, Default) ->
Val = get_opt(host, Opts, fun iolist_to_binary/1, Default),
ejabberd_regexp:greplace(Val, <<"@HOST@">>, Host).
-spec v_db(odbc | mnesia | riak | internal) -> odbc | mnesia | riak.
v_db(odbc) -> odbc;
v_db(internal) -> mnesia;
v_db(mnesia) -> mnesia;
v_db(riak) -> riak.
-spec db_type(opts()) -> odbc | mnesia | riak.
db_type(Opts) ->
@ -217,31 +224,14 @@ db_type(Opts) ->
-spec db_type(binary() | global, atom() | opts()) -> odbc | mnesia | riak.
db_type(Host, Module) when is_atom(Module) ->
get_module_opt(Host, Module, db_type,
fun(odbc) -> odbc;
(internal) -> mnesia;
(mnesia) -> mnesia;
(riak) -> riak
end,
default_db(Host));
get_module_opt(Host, Module, db_type, fun v_db/1, default_db(Host));
db_type(Host, Opts) when is_list(Opts) ->
get_opt(db_type, Opts,
fun(odbc) -> odbc;
(internal) -> mnesia;
(mnesia) -> mnesia;
(riak) -> riak
end,
default_db(Host)).
get_opt(db_type, Opts, fun v_db/1, default_db(Host)).
-spec default_db(binary() | global) -> odbc | mnesia | riak.
default_db(Host) ->
ejabberd_config:get_option({default_db, Host},
fun(odbc) -> odbc;
(mnesia) -> mnesia;
(riak) -> riak;
(internal) -> mnesia
end, mnesia).
ejabberd_config:get_option({default_db, Host}, fun v_db/1, mnesia).
-spec loaded_modules(binary()) -> [atom()].