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/map_loader.rb,
lib/riak/client/beefcake/crdt/set_loader.rb,
lib/riak/client/beefcake/crdt/counter_loader.rb,
lib/riak/client/beefcake/crdt/grow_only_set_loader.rb,
lib/riak/client/beefcake/crdt/hyper_log_log_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, GrowOnlySetLoader, HyperLogLogLoader, 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.



40
41
42
# File 'lib/riak/client/beefcake/crdt_loader.rb', line 40

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.



38
39
40
# File 'lib/riak/client/beefcake/crdt_loader.rb', line 38

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.



38
39
40
# File 'lib/riak/client/beefcake/crdt_loader.rb', line 38

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.



63
64
65
66
67
68
69
# File 'lib/riak/client/beefcake/crdt_loader.rb', line 63

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

  [CounterLoader, HyperLogLogLoader, MapLoader, SetLoader, GrowOnlySetLoader].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.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/riak/client/beefcake/crdt_loader.rb', line 45

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