anchor.diff:  }).
   
   -define(TABLE, build_registry).
  +-record(builderl_build_record, {id, project, ref, committish, state, time}).
   
   %% API.
   
  
positive.code: -module(builderl_build_registry).
  -behaviour(gen_server).
  -compile({parse_transform, lager_transform}).
  
  %% API.
  -export([start_link/0]).
  
negative.code:     SID = uuid:to_string(simple, ID),
      lager:info("Generated ID ~p", [SID]),
      Time = os:system_time(seconds),
      Record = #builderl_build_record{id=ID,
                                      project=Project,
                                      ref=Ref,
                                      committish=Commitish,
                                      state=created,
                                      time=Time},
      ok = dets:insert(?TABLE, Record),
      dets:sync(?TABLE),
  	  {reply, {ok, SID}, State};
  
  handle_call({get_builds, Project}, _From, State) ->
      Match = ets:fun2ms(
              fun(BBR=#builderl_build_record{project=BBRProject}) when BBRProject =:= Project ->
                  BBR
              end),
  
      Objects = dets:select(?TABLE, Match),
      Builds = builds_to_proplist(Objects),
  	  {reply, {ok, Builds}, State};
  
  handle_call({get_build, Project, ID}, _From, State) ->
      BID = uuid:to_binary(ID),
      io:format("ID ~p", [BID]),
      Objects = dets:lookup(?TABLE, ID),
  	  {reply, {ok, Objects}, State};
  
  handle_call(get_projects, _From, State) ->
      Projects = keys(?TABLE),
      {reply, {ok, Projects}, State};
  
  handle_call(_Request, _From, State) ->
  	  {reply, ignored, State}.
  
  builds_to_proplist([{Project, ID, Ref, Commitish, Time}|Rest]) ->
      [[{id, uuid:to_string(simple, ID)},
       {project, Project},
       {ref, Ref},
       {commitish, Commitish},
       {time, Time}]| builds_to_proplist(Rest)];
  builds_to_proplist([#builderl_build_record{project=P, id=ID, ref=R, committish=C, time=T}|Rest]) ->
      [[{id, uuid:to_string(simple, ID)},
       {project, P},
       {ref, R},
       {commitish, C},
       {time, T}]| builds_to_proplist(Rest)];
  
  builds_to_proplist([]) ->
      [].
  
  