~jonn/bed

5553f9b9abbe48d28c6258033ac586900687643b — Jonn 3 years ago e77e86d
Problem: default formatter sucks

Solution:
 - Condifure default formatter to be 80-wide, not inline stuff.

Sadly, we've completely messed up rebar.config and it doesn't seem to be
formattable with rebar3 format. But hey... You win some, you lose some.
M apps/bed/src/bed.app.src => apps/bed/src/bed.app.src +1 -15
@@ 1,15 1,1 @@
{application, bed,
 [{description, "An OTP application"},
  {vsn, "0.1.0"},
  {registered, []},
  {mod, {bed_app, []}},
  {applications,
   [kernel,
    stdlib
   ]},
  {env,[]},
  {modules, []},

  {licenses, ["Apache 2.0"]},
  {links, []}
 ]}.
{ application , bed , [ { description , "An OTP application" } , { vsn , "0.1.0" } , { registered , [ ] } , { mod , { bed_app , [ ] } } , { applications , [ kernel , stdlib ] } , { env , [ ] } , { modules , [ ] } , { licenses , [ "Apache 2.0" ] } , { links , [ ] } ] } .

M apps/bed/src/bed_app.erl => apps/bed/src/bed_app.erl +2 -1
@@ 7,7 7,8 @@

-behaviour(application).

-export([start/2, stop/1]).
-export([start/2,
         stop/1]).

start(_StartType, _StartArgs) ->
    bed_sup:start_link().

M apps/bed/src/bed_io_srv.erl => apps/bed/src/bed_io_srv.erl +9 -4
@@ 3,20 3,25 @@
-behaviour(gen_server).

-export([start_link/0]).
-export([init/1, handle_call/3, handle_cast/2]).
-export([init/1,
         handle_call/3,
         handle_cast/2]).
-export([receive_worker_list_change/2]).

-record(state,
        {sofo_pool_pids = sets:from_list([]) :: sets:set(pid()), chunk_inbox = [] :: [binary()]}).
        {sofo_pool_pids = sets:from_list([]) :: sets:set(pid()),
         chunk_inbox = [] :: [binary()]}).

start_link() ->
    gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

init(_) ->
    bed_sofo_pool:subscribe_to_worker_list_changes_via({?MODULE, receive_worker_list_change}),
    bed_sofo_pool:notify_worker_list_changes_via({?MODULE,
                                                  receive_worker_list_change}),
    {ok, #state{}}.

-spec receive_worker_list_change(Event :: enter | leave, Pids :: sets:set(pid())) ->
-spec receive_worker_list_change(Event :: enter | leave,
                                 Pids :: sets:set(pid())) ->
                                    term().
receive_worker_list_change(Event, Pids) ->
    gen_server:call(?MODULE, {receive_worker_list_change, {Event, Pids}}).

M apps/bed/src/bed_sofo_pool.erl => apps/bed/src/bed_sofo_pool.erl +4 -4
@@ 1,9 1,9 @@
-module(bed_sofo_pool).

-export([subscribe_to_worker_list_changes_via/1]).
-export([notify_worker_list_changes_via/1]).

-spec subscribe_to_worker_list_changes_via({atom(), atom()}) -> 'ok' | {'error', atom()}.
subscribe_to_worker_list_changes_via({Module, Function}) ->
-spec notify_worker_list_changes_via({atom(), atom()}) -> ok | {error, atom()}.
notify_worker_list_changes_via({Module, Function}) ->
    {error, undefined};
subscribe_to_worker_list_changes_via(_) ->
notify_worker_list_changes_via(_) ->
    {error, badarg}.

M apps/bed/src/bed_sofo_worker.erl => apps/bed/src/bed_sofo_worker.erl +1 -1
@@ 1,1 1,1 @@
-module(bed_sofo_worker).
\ No newline at end of file
-module(bed_sofo_worker).

M apps/bed/src/bed_sup.erl => apps/bed/src/bed_sup.erl +5 -2
@@ 76,7 76,8 @@ fan_bytes(BitsPerRule, Workers, FH) ->
                   FH :: file:io_device()) ->
                      {error, undefined}.
fan_bytes_do(BytesToFanOut, Workers, FH) ->
    io:format("Fanning out ~p bytes.~nFrom: ~p~nTo: ~p~n", [BytesToFanOut, Workers, FH]),
    io:format("Fanning out ~p bytes.~nFrom: ~p~nTo: ~p~n",
              [BytesToFanOut, Workers, FH]),
    {error, undefined}.

write_src(FileName, IOListSrc) ->


@@ 93,7 94,9 @@ main_fan() ->

main() ->
    Program =
        [<<"-module(local).">>, <<"-export([main/0]).">>, <<"main() -> io:format(\"hi?\").">>],
        [<<"-module(local).">>,
         <<"-export([main/0]).">>,
         <<"main() -> io:format(\"hi?\").">>],
    FileName = "local.erl",
    StrModuleName = "local",
    write_src(FileName, Program),

M rebar.config => rebar.config +3 -5
@@ 2,12 2,10 @@

{ deps , [ ] } .

{ relx , [
  { release , { bed , "0.1.0" } , [ bed , sasl ] } ,
  { mode , dev } , { sys_config , "./config/sys.config" } ,
  { vm_args , "./config/vm.args" }
] } .
{ relx , [ { release , { bed , "0.1.0" } , [ bed , sasl ] } , { mode , dev } , { sys_config , "./config/sys.config" } , { vm_args , "./config/vm.args" } ] } .

{ profiles , [ { prod , [ { relx , [ { mode , prod } ] } ] } ] } .

{ plugins , [ rebar3_format ] } .

{ format , [ { files , [ "rebar.config" , "apps/bed/src/*.erl" , "apps/bed/src/*.app.src" ] } , { formatter , default_formatter } , { options , #{ paper => 80 , inline_attributes => none , inline_fields => none , inline_items => none } } ] } .