Created
September 28, 2014 04:42
-
-
Save j-mcnally/d4fffbabf015ab3d6d19 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
defmodule RObj do | |
require Record | |
use Riak.Object | |
Record.defrecord :riakobj, [bucket: nil, key: nil, data: nil, metadata: nil, vclock: nil, content_type: "application/json"] | |
def from_robj(robj) do | |
riakobj( | |
bucket: :riakc_obj.bucket(robj), | |
key: :riakc_obj.key(robj), | |
data: :riakc_obj.get_update_value(robj), | |
metadata: :riakc_obj.get_update_metadata(robj), | |
vclock: :riakc_obj.vclock(robj), | |
content_type: :riakc_obj.get_update_content_type(robj)) | |
end | |
def to_robj(obj) do | |
unless obj.key, do: obj = obj.key(:undefined) | |
robj = :riakc_obj.new( | |
obj.bucket, | |
obj.key, | |
obj.data, | |
obj.content_type) | |
if obj.vclock, do: robj = :riakc_obj.set_vclock(robj, obj.vclock) | |
if obj.metadata, do: robj = :riakc_obj.update_metadata(robj, obj.metadata) | |
robj | |
end | |
def create(), do: riakobj() | |
def create(args) do | |
Enum.to_list(args) |> | |
riakobj |> | |
to_robj |> | |
from_robj | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment