Wrap the rest of the object modules in elixir
This commit is contained in:
15
lib/geef.ex
Normal file
15
lib/geef.ex
Normal file
@@ -0,0 +1,15 @@
|
||||
defmodule Geef do
|
||||
|
||||
defmacro __using__(_) do
|
||||
quote do
|
||||
alias Geef.Repository
|
||||
alias Geef.Reference
|
||||
alias Geef.Object
|
||||
alias Geef.Commit
|
||||
alias Geef.Tree
|
||||
alias Geef.Blob
|
||||
alias Geef.Tag
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
21
lib/geef/blob.ex
Normal file
21
lib/geef/blob.ex
Normal file
@@ -0,0 +1,21 @@
|
||||
defmodule Geef.Blob do
|
||||
alias Geef.Object
|
||||
|
||||
def lookup(repo, id) do
|
||||
case :geef_obj.lookup(repo, id) do
|
||||
{:ok, obj} ->
|
||||
{:ok, Object.new obj}
|
||||
error ->
|
||||
error
|
||||
end
|
||||
end
|
||||
|
||||
def size(obj = Object[type: :blob]) do
|
||||
:geef_blob.size(set_elem(obj, 0, :geef_object))
|
||||
end
|
||||
|
||||
def content(obj = Object[type: :blob]) do
|
||||
:geef_blob.content(set_elem(obj, 0, :geef_object))
|
||||
end
|
||||
|
||||
end
|
||||
17
lib/geef/commit.ex
Normal file
17
lib/geef/commit.ex
Normal file
@@ -0,0 +1,17 @@
|
||||
defmodule Geef.Commit do
|
||||
alias Geef.Object
|
||||
|
||||
def lookup(repo, id) do
|
||||
case :geef_commit.lookup(repo, id) do
|
||||
{:ok, commit} ->
|
||||
{:ok, Object.new commit}
|
||||
error ->
|
||||
error
|
||||
end
|
||||
end
|
||||
|
||||
def tree_id(commit = Object[type: :commit]) do
|
||||
:geef_commit.tree_id(set_elem(commit, 0, :geef_object))
|
||||
end
|
||||
|
||||
end
|
||||
@@ -3,5 +3,7 @@ defmodule Geef.Odb do
|
||||
:geef_odb.exists(pid, id)
|
||||
end
|
||||
|
||||
def write(pid, content, type), do: :geef_odb.write(pid, content, type)
|
||||
|
||||
def stop(pid), do: :geef_odb.stop(pid)
|
||||
end
|
||||
|
||||
17
lib/geef/tree.ex
Normal file
17
lib/geef/tree.ex
Normal file
@@ -0,0 +1,17 @@
|
||||
defmodule Geef.Tree do
|
||||
alias Geef.Object
|
||||
|
||||
def lookup(repo, id) do
|
||||
case :geef_tree.lookup(repo, id) do
|
||||
{:ok, obj} ->
|
||||
{:ok, Object.new obj}
|
||||
error ->
|
||||
error
|
||||
end
|
||||
end
|
||||
|
||||
def get(tree = Object[type: :tree], path) do
|
||||
:geef_tree.get(set_elem(tree, 0, :geef_object), path)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -6,16 +6,12 @@
|
||||
|
||||
-include("geef_records.hrl").
|
||||
|
||||
-export([lookup/2, id/1, size/1, content/1]).
|
||||
-export([lookup/2, size/1, content/1]).
|
||||
|
||||
-spec lookup(pid(), geef_oid() | iolist()) -> geef_object().
|
||||
lookup(Repo, Id) ->
|
||||
geef_obj:lookup(Repo, Id, blob).
|
||||
|
||||
-spec id(geef_object()) -> geef_oid().
|
||||
id(Obj = #geef_object{type=blob}) ->
|
||||
geef_obj:id(Obj).
|
||||
|
||||
size(#geef_object{type=blob, handle=Handle}) ->
|
||||
geef_nif:blob_size(Handle).
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
-module(geef_commit).
|
||||
-export([tree_id/1, tree/1, id/1, lookup/2]).
|
||||
-export([tree_id/1, tree/1, lookup/2]).
|
||||
|
||||
-include("geef_records.hrl").
|
||||
|
||||
@@ -18,7 +18,4 @@ tree(#geef_object{type=commit,handle=Handle}) ->
|
||||
|
||||
-spec lookup(pid(), geef_oid() | iolist()) -> geef_object().
|
||||
lookup(Repo, Id) ->
|
||||
geef_object:lookup(Repo, Id, commit).
|
||||
|
||||
id(Obj = #geef_object{type=commit}) ->
|
||||
geef_object:id(Obj).
|
||||
geef_obj:lookup(Repo, Id, commit).
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-endif.
|
||||
|
||||
-export([get/2, id/1, lookup/2]).
|
||||
-export([get/2, lookup/2]).
|
||||
|
||||
-include("geef_records.hrl").
|
||||
|
||||
@@ -17,10 +17,6 @@ get(#geef_object{type=tree,handle=Handle}, Path) ->
|
||||
Other
|
||||
end.
|
||||
|
||||
-spec id(geef_object()) -> {ok, geef_oid()} | {error, term()}.
|
||||
id(Obj = #geef_object{type=tree}) ->
|
||||
geef_object:id(Obj).
|
||||
|
||||
-spec lookup(pid(), geef_oid() | iolist()) -> {ok, geef_object()} | {error, term()}.
|
||||
lookup(Repo, Id) ->
|
||||
geef_obj:lookup(Repo, Id, tree).
|
||||
|
||||
Reference in New Issue
Block a user