Simplify machinery_mg_backend:new/2 usage (#3)

This commit is contained in:
Anton Belyaev 2018-05-31 18:42:18 +03:00 committed by GitHub
parent fa6ea4cd01
commit 4b582b951e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 14 deletions

View File

@ -62,17 +62,11 @@ get_backend_config() ->
%% client
-spec get_backend(opts()) ->
machinery_mg_backend:backend().
get_backend(Opts) ->
machinery_mg_backend:new(get_backend_opts(Opts)).
-spec get_backend_opts(opts()) ->
machinery_mg_backend:backend_opts().
get_backend_opts(#{woody_ctx := WoodyCtx}) ->
#{
woody_ctx => WoodyCtx,
get_backend(#{woody_ctx := WoodyCtx}) ->
machinery_mg_backend:new(WoodyCtx, #{
client => get_woody_client(),
schema => config(schema)
}.
}).
-spec get_woody_client() ->
machinery_mg_client:woody_client().

View File

@ -30,7 +30,6 @@
backend_config := backend_config()
}.
-type handler(A) :: {logic_handler(A), handler_config()}. %% handler server spec
-type handler_opts() :: machinery:handler_opts(#{
@ -51,6 +50,11 @@
-type backend() :: {?MODULE, backend_opts()}.
-type backend_opts_static() :: #{
client := machinery_mg_client:woody_client(),
?BACKEND_CORE_OPTS
}.
-export_type([backend_config/0]).
-export_type([handler_config/0]).
-export_type([logic_handler/1]).
@ -62,7 +66,7 @@
%% API
-export([get_routes/2]).
-export([get_handler/2]).
-export([new/1]).
-export([new/2]).
%% Machinery backend
-behaviour(machinery_backend).
@ -91,10 +95,10 @@ get_handler({LogicHandler, #{path := Path, backend_config := Config}}, _) ->
{?MODULE, get_backend_handler_opts(LogicHandler, Config)}
}}.
-spec new(backend_opts()) ->
-spec new(woody_context:ctx(), backend_opts_static()) ->
backend().
new(Opts = #{woody_ctx := _, client := _, schema := _}) ->
{?MODULE, Opts}.
new(WoodyCtx, Opts = #{client := _, schema := _}) ->
{?MODULE, Opts#{woody_ctx => WoodyCtx}}.
%% Machinery backend