Add lookup/2 to the specific types
They proxy to geef_object:lookup/3 which looks up the object and asserts the type.
This commit is contained in:
@@ -6,19 +6,29 @@
|
||||
|
||||
-include("geef_records.hrl").
|
||||
|
||||
-export([lookup/2, id/1]).
|
||||
-export([lookup/2, lookup/3, id/1]).
|
||||
|
||||
-spec lookup(pid(), oid() | iolist()) -> object().
|
||||
-spec lookup(pid(), oid() | iolist()) -> {ok, object()} | {error, term()}.
|
||||
lookup(Repo, #oid{oid=Oid}) ->
|
||||
case geef_repo:lookup_object(Repo, Oid) of
|
||||
{ok, Type, Handle} ->
|
||||
{ok, #object{type=Type, handle=Handle}};
|
||||
Other ->
|
||||
Other
|
||||
{error, Err} ->
|
||||
{error, Err}
|
||||
end;
|
||||
lookup(Repo, Id) ->
|
||||
lookup(Repo, geef_oid:parse(Id)).
|
||||
|
||||
%% As lookup/2, but it asserts that the type is correct
|
||||
-spec lookup(pid(), oid() | iolist(), atom()) -> {ok, object()} | {error, term()}.
|
||||
lookup(Repo, Id, Type) ->
|
||||
case lookup(Repo, Id) of
|
||||
{ok, Obj = #object{type=Type}} ->
|
||||
{ok, Obj};
|
||||
{error, Err} ->
|
||||
{error, Err}
|
||||
end.
|
||||
|
||||
id(#object{handle=Handle}) ->
|
||||
case geef:object_id(Handle) of
|
||||
{ok, Oid} ->
|
||||
|
||||
Reference in New Issue
Block a user