class Riak::Crdt::InnerCounter

The {InnerCounter} lives inside a {Map}, or an {InnerMap} inside of a {Map}, and is accessed through a {TypedCollection}.

Much like the {Riak::Crdt::Counter}, it provides an integer value that can be incremented and decremented.

Attributes

name[RW]

The name of this counter inside a map.

@api private

parent[R]

The parent of this counter.

@api private

to_i[R]

The value of this counter.

@return [Integer] counter value

value[R]

The value of this counter.

@return [Integer] counter value

Public Class Methods

delete() click to toggle source

@api private

# File lib/riak/crdt/inner_counter.rb, line 74
def self.delete
  Operation::Delete.new.tap do |op|
    op.type = :counter
  end
end
new(parent, value = 0) click to toggle source

@api private

# File lib/riak/crdt/inner_counter.rb, line 26
def initialize(parent, value = 0)
  @parent = parent
  @value = value
end
update(increment) click to toggle source

@api private

# File lib/riak/crdt/inner_counter.rb, line 66
def self.update(increment)
  Operation::Update.new.tap do |op|
    op.value = increment
    op.type = :counter
  end
end

Public Instance Methods

batch() { |batcher| ... } click to toggle source

Perform multiple increments against this counter, and collapse them into a single operation.

@yieldparam [BatchCounter] batch_counter actually collects the

operations.
# File lib/riak/crdt/inner_counter.rb, line 50
def batch
  batcher = BatchCounter.new

  yield batcher

  increment batcher.accumulator
end
decrement(amount = 1) click to toggle source

Decrement the counter. Opposite of increment.

@param [Integer] amount How much to decrement from the counter.

# File lib/riak/crdt/inner_counter.rb, line 41
def decrement(amount = 1)
  increment -amount
end
increment(amount = 1) click to toggle source

Increment the counter.

@param [Integer] amount How much to increment the counter by.

# File lib/riak/crdt/inner_counter.rb, line 34
def increment(amount = 1)
  @parent.increment name, amount
end
pretty_print(pp) click to toggle source
# File lib/riak/crdt/inner_counter.rb, line 58
def pretty_print(pp)
  pp.object_group self do
    pp.breakable
    pp.pp value
  end
end