forked from mbbx6spp/rebar-templates
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Template for Finsignia compliant gen_server.
Used with rebar create subcommand we can generate a initial gen_server that complies with Finsignia internal coding standards/style guidelines. To generate run: % rebar create template=finsrv server_name=server_name_minus_srv \ description="Manages connections to database...." \ author_name="Your Name" author_email="user@domain.com"
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
%%%' HEADER | ||
%%% @author {{author_name}} <{{author_name}}> | ||
%%% @copyright {{copyright_year}} {{author_name}} | ||
%%% @doc gen_server callback module implementation: | ||
%%% {{description}} | ||
%%% @end | ||
-module({{name}}_srv). | ||
-author('{{author_name}} <{{author_email}}>'). | ||
|
||
-behaviour(gen_server). | ||
|
||
-export([start_link/0]). | ||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2]). | ||
-export([code_change/3]). | ||
-export([stop/0, terminate/2]). | ||
|
||
-ifdef(TEST). | ||
-compile(export_all). | ||
-endif. | ||
|
||
% TODO: If unnamed server, remove definition below. | ||
-define(SERVER, ?MODULE). | ||
%%%. | ||
%%%' PUBLIC API | ||
|
||
%% @doc starts gen_server implementation and caller links to the process too. | ||
%% @spec start_link() -> {ok, Pid} | ignore | {error, Error} | ||
%% where | ||
%% Pid = pid(), | ||
%% Error = {already_started, Pid} | term() | ||
start_link() -> | ||
% TODO: decide whether to name gen_server callback implementation or not. | ||
% gen_server:start_link(?MODULE, [], []). % for unnamed gen_server | ||
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). | ||
|
||
% TODO: add more public API here... | ||
|
||
%%%. | ||
%%%' CALLBACKS | ||
%% @private | ||
init(State) -> | ||
{ok, State}. | ||
|
||
%% @private | ||
handle_call(_Req, _From, State) -> | ||
{reply, State}. | ||
|
||
%% @private | ||
handle_cast(stop, State) -> | ||
{stop, normal, State}; | ||
handle_cast(_Req, State) -> | ||
{noreply, State}. | ||
|
||
%% @private | ||
handle_info(_Info, State) -> | ||
{noreply, State}. | ||
|
||
%% @private | ||
code_change(_OldVsn, State, _Extra) -> | ||
{ok, State}. | ||
|
||
%% @private | ||
stop() -> | ||
gen_server:cast(?MODULE, stop). | ||
|
||
%% @private | ||
terminate(normal, _State) -> | ||
ok; | ||
terminate(shutdown, _State) -> | ||
ok; | ||
terminate({shutdown, _Reason}, _State) -> | ||
ok; | ||
terminate(Reason, _State) -> | ||
ok. | ||
|
||
%%%. | ||
%%%' PRIVATE FUNCTIONS | ||
% TODO: Add private helper functions here. | ||
|
||
%%%. | ||
%%% vim: set filetype=erlang tabstop=2 foldmarker=%%%',%%%. foldmethod=marker: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{variables, [ | ||
{name, "myserver"}, | ||
{author_name, "Susan Potter"}, | ||
{author_email, "me@susanpotter.net"}]}. | ||
{template, "gen_server.erl", "src/{{name}}.erl"}. |