Class: Riak::Crdt::Base Private

Inherits:
Object show all
Includes:
Util::Translation
Defined in:
lib/riak/crdt/base.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.

Basic and shared code used by the top-level CRDTs. In particular, dirty- tracking, loading, and operating is implemented by this class, and the Set, HyperLogLog, Counter, and Map classes implement everything else.

Direct Known Subclasses

Counter, HyperLogLog, Map, Set

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Translation

#i18n_scope, #t

Constructor Details

#initialize(bucket, key, bucket_type, options = {}) ⇒ Base

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.

Base CRDT initialization The bucket type is determined by the first of these sources:

  1. The ‘bucket_type` String argument

  2. A BucketTyped::Bucket as the ‘bucket` argument

  3. A ‘bucket_type` Symbol argument is looked up in the `Crdt::Base::DEFAULT_BUCKET_TYPES` hash

Parameters:



33
34
35
36
37
38
39
40
# File 'lib/riak/crdt/base.rb', line 33

def initialize(bucket, key, bucket_type, options = {})
  configure_bucket bucket
  configure_key key
  configure_bucket_type bucket_type
  @options = options

  @dirty = true
end

Instance Attribute Details

#bucketObject (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.



11
12
13
# File 'lib/riak/crdt/base.rb', line 11

def bucket
  @bucket
end

#bucket_typeObject (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.



12
13
14
# File 'lib/riak/crdt/base.rb', line 12

def bucket_type
  @bucket_type
end

#keyObject (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.

Returns the key of this CRDT. Extremely useful when using a Riak-assigned key.



16
17
18
# File 'lib/riak/crdt/base.rb', line 16

def key
  @key
end

Instance Method Details

#==(other) ⇒ 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.



64
65
66
67
68
69
70
# File 'lib/riak/crdt/base.rb', line 64

def ==(other)
  return false unless self.class == other.class
  return false unless self.bucket_type == other.bucket_type
  return false unless self.bucket == other.bucket
  return false unless self.key == other.key
  return true
end

#context?Boolean

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.

Does this CRDT have the context necessary to remove elements?

Returns:

  • (Boolean)

    if the set has a defined context



60
61
62
# File 'lib/riak/crdt/base.rb', line 60

def context?
  !!@context
end

#dirty?Boolean

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:

  • (Boolean)


42
43
44
# File 'lib/riak/crdt/base.rb', line 42

def dirty?
  @dirty
end

#inspect_nameObject

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.



92
93
94
95
# File 'lib/riak/crdt/base.rb', line 92

def inspect_name
  "#<#{self.class.name} bucket=#{@bucket.name} " \
  "key=#{@key} type=#{@bucket_type}>"
end

#pretty_print(pp) ⇒ 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.



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/riak/crdt/base.rb', line 72

def pretty_print(pp)
  pp.object_group self do
    pp.breakable
    pp.text "bucket_type=#{@bucket_type}"
    pp.comma_breakable
    pp.text "bucket=#{@bucket.name}"
    pp.comma_breakable
    pp.text "key=#{@key}"

    yield
  end
end

#pretty_print_cycle(pp) ⇒ 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.



85
86
87
88
89
90
# File 'lib/riak/crdt/base.rb', line 85

def pretty_print_cycle(pp)
  pp.object_group self do
    pp.breakable
    pp.text "#{@bucket_type}/#{@bucket.name}/#{@key}"
  end
end

#reloadObject

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.

Force a reload of this structure from Riak.



47
48
49
50
51
52
53
54
55
# File 'lib/riak/crdt/base.rb', line 47

def reload
  loader do |l|
    vivify l.load @bucket, @key, @bucket_type
    @context = l.context
  end
  @dirty = false

  self
end