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, GrowOnlySet, HyperLogLog, Map

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:



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

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.



25
26
27
# File 'lib/riak/crdt/base.rb', line 25

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.



26
27
28
# File 'lib/riak/crdt/base.rb', line 26

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.



30
31
32
# File 'lib/riak/crdt/base.rb', line 30

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.



78
79
80
81
82
83
84
# File 'lib/riak/crdt/base.rb', line 78

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



74
75
76
# File 'lib/riak/crdt/base.rb', line 74

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)


56
57
58
# File 'lib/riak/crdt/base.rb', line 56

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.



106
107
108
109
# File 'lib/riak/crdt/base.rb', line 106

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.



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/riak/crdt/base.rb', line 86

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.



99
100
101
102
103
104
# File 'lib/riak/crdt/base.rb', line 99

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.



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

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

  self
end