Module: Riak::Client::BeefcakeProtobuffsBackend::ObjectMethods

Included in:
Riak::Client::BeefcakeProtobuffsBackend
Defined in:
lib/riak/client/beefcake/object_methods.rb

Constant Summary collapse

ENCODING =
"Riak".respond_to?(:encoding)

Instance Method Summary collapse

Instance Method Details

#dump_object(robject, options = {}) ⇒ Object

Returns RpbPutReq



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/riak/client/beefcake/object_methods.rb', line 12

def dump_object(robject, options = {})
  req_opts = options.merge(:bucket => maybe_encode(robject.bucket.name))
  if robject.bucket.respond_to?(:type) && t = robject.bucket.type
    req_opts[:type] = maybe_encode(t.name)
  end
  pbuf = RpbPutReq.new(req_opts)
  pbuf.key = maybe_encode(robject.key) if robject.key # Put w/o key supported!
  pbuf.vclock = maybe_encode(Base64.decode64(robject.vclock)) if robject.vclock
  dump_content pbuf, robject
  pbuf
end

#load_object(pbuf, robject) ⇒ Object

Returns RObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/riak/client/beefcake/object_methods.rb', line 25

def load_object(pbuf, robject)
  return robject if pbuf.respond_to?(:unchanged) && pbuf.unchanged # Reloading
  robject.vclock = Base64.encode64(pbuf.vclock).chomp if pbuf.vclock
  robject.key = maybe_unescape(pbuf.key) if pbuf.respond_to?(:key) && pbuf.key # Put w/o key
  robject.siblings = (pbuf.content || []).map do |c|
    RContent.new(robject) do |sibling|
      load_content(c, sibling)
    end
  end
  robject.conflict? ? robject.attempt_conflict_resolution : robject
end