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
The name of this counter inside a map.
@api private
The parent of this counter.
@api private
The value of this counter.
@return [Integer] counter value
The value of this counter.
@return [Integer] counter value
Public Class Methods
@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
@api private
# File lib/riak/crdt/inner_counter.rb, line 26 def initialize(parent, value = 0) @parent = parent @value = value end
@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
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 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 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
# 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