Class: Riak::Client::BeefcakeProtobuffsBackend::CrdtLoader Private

Inherits:
Object
  • Object
show all
Includes:
Util::Translation
Defined in:
lib/riak/client/beefcake/crdt_loader.rb,
lib/riak/client/beefcake/crdt/set_loader.rb,
lib/riak/client/beefcake/crdt/map_loader.rb,
lib/riak/client/beefcake/crdt/counter_loader.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Loads, and deserializes CRDTs from protobuffs into Ruby hashes, sets, strings, and integers.

Defined Under Namespace

Classes: CounterLoader, MapLoader, SetLoader

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Translation

#i18n_scope, #t

Constructor Details

#initialize(backend) ⇒ CrdtLoader

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CrdtLoader


24
25
26
# File 'lib/riak/client/beefcake/crdt_loader.rb', line 24

def initialize(backend)
  @backend = backend
end

Instance Attribute Details

#backendObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


22
23
24
# File 'lib/riak/client/beefcake/crdt_loader.rb', line 22

def backend
  @backend
end

#contextObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


22
23
24
# File 'lib/riak/client/beefcake/crdt_loader.rb', line 22

def context
  @context
end

Instance Method Details

#get_loader_for_value(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


47
48
49
50
51
52
53
# File 'lib/riak/client/beefcake/crdt_loader.rb', line 47

def get_loader_for_value(value)
  return nil if value.nil?

  [CounterLoader, MapLoader, SetLoader].map do |loader|
    loader.for_value value
  end.compact.first
end

#load(bucket, key, bucket_type, options = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Perform the protobuffs request and return a deserialized CRDT.


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/riak/client/beefcake/crdt_loader.rb', line 29

def load(bucket, key, bucket_type, options = {})
  bucket = bucket.name if bucket.is_a? ::Riak::Bucket
  fetch_args = options.merge(
                             bucket: bucket,
                             key: key,
                             type: bucket_type
                             )
  request = DtFetchReq.new fetch_args

  response = backend.protocol do |p|
    p.write :DtFetchReq, request
    p.expect :DtFetchResp, DtFetchResp
  end

  @context = response.context
  rubyfy response
end