Skip to content

Commit

Permalink
applications/yapp: Update edoc
Browse files Browse the repository at this point in the history
Fix warnings using deprecated @SPEC and @type edoc tags.
  • Loading branch information
avtobiff authored and vinoski committed Jun 14, 2022
1 parent 44623b0 commit d54b360
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 50 deletions.
58 changes: 28 additions & 30 deletions applications/yapp/src/yapp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,23 @@
%%% <p><em>Note2:</em> The current available registry implementation uses Mnesia so you need
%%% to create a mnesia schema (if not already done) for the node(s) you are running Yaws on.
%%% <code>mnesia:create_schema([node()]).</code></p>
%%%
%%% @type yawsArg() = term(). This is the #arg record as defined
%%% by yaws_api.hrl.
%%%
%%% @type yawsSconf() = term(). This is the #sconf record as defined
%%% by yaws.hrl.
%%%
%%% @type yawsGconf() = term(). This is the #gconf record as defined
%%% by yaws.hrl.

-module(yapp).
-author('[email protected]').

-include("yaws_api.hrl").
-export([arg_rewrite/1, start/0, prepath/1, insert/1, insert/2, remove/2,
log/3,
reset_yaws_conf/0, srv_id/1,
get_bootstrap_yapps/0, get_yapps/0, get_server_ids/0]).
%% reload_yaws/0,

-include("yaws_api.hrl").
-include("yaws.hrl").

-type yawsArg() :: #arg{}. %% The #arg record as defined by yaws_api.hrl.
-type yawsSconf() :: #sconf{}. %% The #sconf record as defined by yaws.hrl.
-type yawsGconf() :: #gconf{}. %% The #gconf record as defined by yaws.hrl.

-define(prepath, yapp_prepath).
-define(srv_id, "yapp_server_id").
-define(bootstrap_yapps, "bootstrap_yapps"). %% Opaque key for "bootstrap yapps"
Expand All @@ -90,7 +87,7 @@
%% yapps is a list of {UrlPath, AppName} tuples
%% UrlPath = string()
%% Interface arg_rewrite_mod
%% @spec arg_rewrite(Arg::yawsArg()) -> yawsArg()
-spec arg_rewrite(Arg :: yawsArg()) -> yawsArg().
%% @doc Interface function for a Yaws arg_rewrite_mod. If
%% it finds a registered Yapp it will strip of the
%% path up to the Yapp and redirect the docroot.
Expand Down Expand Up @@ -138,7 +135,7 @@ arg_rewrite(Arg) ->


%% Interface run_mod
%% @spec start() -> void()
-spec start() -> ok | {error, Reason :: term()}.
%% @doc Interface function for Yaws run_mod.
%% This fun is spawned from Yaws so no return val is expected.
%% All Yapps can expect mnesia to be started, so mnesia is ensured
Expand Down Expand Up @@ -172,17 +169,17 @@ wait_for_yaws(N) ->
end.


%% @spec prepath(Arg::yawsArg()) -> Path::string()
-spec prepath(Arg :: yawsArg()) -> Path :: string().
%% @doc Get the Yapp root-path. Can be called from a Yapp erl/1
%% fun or an erl section in a .yaws file to get the Yapp root
%% path.
prepath(Arg) ->
Arg#arg.docroot_mount.


%% @spec log(Level, FormatStr::string(), Args) -> void()
%% Level = error | warning | info | debug
%% Args = [term()]
-spec log(Level, FormatStr :: string(), Args :: [term()]) -> ok
when
Level :: error | warning | info | debug.
%% @doc Yapp interface to the error_logger.
log(debug, FormatStr, Args) ->
gen_event:notify(error_logger, {debug_msg, group_leader(), {self(), FormatStr, Args}});
Expand Down Expand Up @@ -364,23 +361,22 @@ reset_yaws_conf() ->
Err
end.

%% @spec get_conf() -> {ok,yawsGconf(), Sconfs}
%% Sconfs = [ yawsSconf() ]
-spec get_conf() -> {ok, yawsGconf(), Sconfs :: [yawsSconf()]}.
get_conf() ->
yaws_api:getconf().
% yaws_config:load(yaws_sup:get_app_args()).

%% @spec srv_id(Sconf) -> string() | undefined
%% Sconf = yawsSconf()
-spec srv_id(Sconf :: yawsSconf()) -> string() | undefined.
%% @doc Get the server id from an Sconf if available
srv_id(SC) ->
OP = yaws:sconf_opaque(SC),
proplists:get_value(?srv_id, OP).

%% @spec get_bootstrap_yapps() -> [{ ServerId, [ {Path, ApplicationName}]}]
%% ServerId = string()
%% Path = string()
%% Applicationame = atom()
-spec get_bootstrap_yapps() -> [{ServerId, [{Path, ApplicationName}]}]
when
ServerId :: string(),
Path :: string(),
ApplicationName :: atom().
%% @doc Gets the Yapps defined in each opaque
%% "bootstrap_yapps = appname1, appname2" for every server id. (If available).
%% Bootstrap yapps will get the same pathname as their application name
Expand Down Expand Up @@ -410,11 +406,13 @@ make_yapp_tuple(A) ->
B = string:strip(A),
{"/" ++ B, list_to_atom(B)}.

%% @spec get_yapps() -> [{ServId,[{yapp, Urlpath, Docroot, Appname , Appmods}]}]
%% Urlpath = string()
%% Docroot = string()
%% Appname = atom()
%% Appmods = [atom()]
-spec get_yapps() -> [{ServerId,[{yapp, Urlpath, Docroot, Appname , Appmods}]}]
when
ServerId :: string(),
Urlpath :: string(),
Docroot :: string(),
Appname :: atom(),
Appmods :: [atom()].
%% @doc Gets all Yapps that are configured for the Yaws server.
get_yapps() ->
{ok, _Gconf, Sconfs} = yaws_api:getconf(),
Expand All @@ -425,7 +423,7 @@ get_yapps() ->
end || SC <- lists:flatten(Sconfs)],
[{S,Y} || {S,Y} <- Yapps1, Y =/= undefined, S =/= undefined].

%% @spec get_server_ids() -> [string()]
-spec get_server_ids() -> [ServerId :: string()].
%% @doc Lists all server ids.
get_server_ids() ->
{ok, _Gconf, Sconfs} = get_conf(),
Expand Down
18 changes: 8 additions & 10 deletions applications/yapp/src/yapp_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,38 @@
%% API
-export([list/2, add/3, add/4, remove/3, init_yapps/1]).

%% @spec list(YappServer::pid(), SrvId) -> Yapps | exit()
%% SrvID = string() | all
%% Yapps = {URL, AppName} | undefined
%% URL= string()
%% AppName = atom()
-spec list(YappServer :: pid(), YawsServerId :: string() | all) ->
Yapps :: {URL :: string(), AppName :: atom()} | undefined.
%% @doc Lists all registered Yapps.
list(YappServer, YawsServerId) ->
gen_server:call(YappServer,{?MODULE, list, YawsServerId}).

%% @spec add(YappServer::pid(), SrvId::string(), YappUrl::string(), AppName::atom()) -> ok | exit()
-spec add(YappServer :: pid(), SrvId :: string(),
YappUrl :: string(), AppName :: atom()) -> ok.
%% @doc Add a Yapp. Adds in the virtual server with the opaque property
%% yapp_server_id = SrvID. The YappUrl is the root path to the Yapp and the AppName is
%% the Name of the application.
add(YappServer, SrvId, YappUrl, AppName) ->
gen_server:call(YappServer,{?MODULE, add, {SrvId, YappUrl, AppName}}).

%% @spec add(YappServer::pid(), SrvId::string(), AppName::atom()) -> ok | exit()
-spec add(YappServer :: pid(), SrvId :: string(), AppName :: atom()) -> ok.
%% @doc Add a Yapp. Adds in the virtual server with the opaque property
%% yapp_server_id = SrvID. The root URL will become "/" ++ atom_to_list(AppName)
%% the Name of the application.
add(YappServer, SrvId, AppName) ->
add(YappServer, SrvId, "/" ++ atom_to_list(AppName), AppName).


%% @spec remove(YappServer::pid(), SrvId::string(), YappUrlOrName::string()) -> ok | exit()
%% YappUrlOrName = string() | atom()
-spec remove(YappServer :: pid(), SrvId :: string(),
YappUrlOrName :: string() | atom()) -> ok.
%% @doc Remove a Yapp from Yaws. Removes in the virtual server with yapp_server_id = SrvID.
%% The YappUrlOrName is either the root path to the Yapp or the name of it.
remove(YappServer, SrvId, YappUrlOrName) when is_list(YappUrlOrName)->
gen_server:call(YappServer,{?MODULE, remove, {SrvId, YappUrlOrName}});
remove(YappServer, SrvId, YappUrlOrName) when is_atom(YappUrlOrName)->
remove(YappServer, SrvId, "/" ++ atom_to_list(YappUrlOrName)).

%% @spec init_yapps(YappServer::pid()) -> ok | exit()
-spec init_yapps(YappServer :: pid()) -> ok.
%% @doc Iinitalizes the Yaws Sconfs list with bootstrap_yapps and Yapps in the
%% the registry. The default name for YappServer is the atom yapp_handler.
init_yapps(YappServer) ->
Expand Down
6 changes: 4 additions & 2 deletions applications/yapp/src/yapp_mnesia_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ list_yapps() ->
{atomic, Value} = mnesia:transaction(fun() -> get_yapp_reg() end),
Value.

%% @spec register_yapp(SrvId::string(), {YappUrl::string(), AppName::atom()}) -> ok | exit()
-spec register_yapp(SrvId :: string(), KeyValue) -> ok
when
KeyValue :: {YappUrl :: string(), AppName :: atom()}.
%% @doc Register a Yapp. Registers in the virtual server with the opaque property
%% yapp_server_id = SrvID. The YappUrl is the root path to the Yapp and the AppName is
%% the Name of the application.
Expand All @@ -181,7 +183,7 @@ register2(SrvId, {YappUrl, AppName}) ->
put_yapp_reg(YR2).


%% @spec unregister_yapp(SrvId::string(), YappUrl::string()) -> ok | exit()
-spec unregister_yapp(SrvId :: string(), YappUrl :: string()) -> ok.
%% @doc Unregister a Yapp. Unregisters in the virtual server with yapp_server_id = SrvID.
%% The YappUrl is the root path to the Yapp.
unregister_yapp(SrvId, YappUrl) ->
Expand Down
20 changes: 12 additions & 8 deletions applications/yapp/src/yapp_registry.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,29 @@
%% API
-export([list/1, register/3, unregister/3]).

%% @spec list(YappRegistry::pid()) -> RegistryContent | exit()
%% RegsitryContent = [YawsSrvContent]
%% YawsSrvContent = {YawsServerId, Yapps}
%% Yapps = [{URL, AppName}] | undefined
%% URL= string()
%% AppName = atom()
-spec list(YappRegistry :: pid()) -> RegistryContent
when
RegistryContent :: [YawsSrvContent],
YawsSrvContent :: {YawsServerId, Yapps},
YawsServerId :: string(),
Yapps :: [{URL, AppName}] | undefined,
URL :: string(),
AppName :: atom().
%% @doc Lists all registered Yapps.
list(YappRegistry) ->
gen_server:call(YappRegistry,{?MODULE, list}).

%% @spec register(YappRegistry::pid(), SrvId::string(), {YappUrl::string(), AppName::atom()}) -> ok | exit()
-spec register(YappRegistry :: pid(), SrvId :: string(),
{YappUrl ::string (), AppName :: atom()}) -> ok.
%% @doc Register a Yapp. Registers in the virtual server with the opaque property
%% yapp_server_id = SrvID. The YappUrl is the root path to the Yapp and the AppName is
%% the Name of the application.
register(YappRegistry, SrvId, {_YappUrl, _AppName} = A) ->
gen_server:call(YappRegistry,{?MODULE, register, {SrvId, A}}).


%% @spec unregister(YappRegistry::pid(), SrvId::string(), YappUrl::string()) -> ok | exit()
-spec unregister(YappRegistry :: pid(), SrvId :: string(),
YappUrl :: string()) -> ok.
%% @doc Unregister a Yapp from Yaws. Unregisters in the virtual server with yapp_server_id = SrvID.
%% The YappUrlOrName is either the root path to the Yapp or the name of it.
unregister(YappRegistry, SrvId, YappUrl) ->
Expand Down

0 comments on commit d54b360

Please sign in to comment.