Class: Riak::Crdt::InnerCounter
- Defined in:
- lib/riak/crdt/inner_counter.rb
Overview
The InnerCounter lives inside a Map, or an InnerMap inside of a Map, and is accessed through a TypedCollection.
Much like the Counter, it provides an integer value that can be incremented and decremented.
Instance Attribute Summary collapse
-
#name ⇒ Object
private
The name of this counter inside a map.
-
#parent ⇒ Object
readonly
private
The parent of this counter.
-
#value ⇒ Integer
(also: #to_i)
readonly
The value of this counter.
Class Method Summary collapse
- .delete ⇒ Object private
- .update(increment) ⇒ Object private
Instance Method Summary collapse
-
#batch {|batch_counter| ... } ⇒ Object
Perform multiple increments against this counter, and collapse them into a single operation.
-
#decrement(amount = 1) ⇒ Object
Decrement the counter.
-
#increment(amount = 1) ⇒ Object
Increment the counter.
-
#initialize(parent, value = 0) ⇒ InnerCounter
constructor
private
A new instance of InnerCounter.
- #pretty_print(pp) ⇒ Object
Constructor Details
#initialize(parent, value = 0) ⇒ InnerCounter
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 InnerCounter.
40 41 42 43 |
# File 'lib/riak/crdt/inner_counter.rb', line 40 def initialize(parent, value = 0) @parent = parent @value = value end |
Instance Attribute Details
#name ⇒ 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.
The name of this counter inside a map.
26 27 28 |
# File 'lib/riak/crdt/inner_counter.rb', line 26 def name @name end |
#parent ⇒ Object (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.
The parent of this counter.
37 38 39 |
# File 'lib/riak/crdt/inner_counter.rb', line 37 def parent @parent end |
#value ⇒ Integer (readonly) Also known as: to_i
The value of this counter.
31 32 33 |
# File 'lib/riak/crdt/inner_counter.rb', line 31 def value @value end |
Class Method Details
.delete ⇒ 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.
88 89 90 91 92 |
# File 'lib/riak/crdt/inner_counter.rb', line 88 def self.delete Operation::Delete.new.tap do |op| op.type = :counter end end |
.update(increment) ⇒ 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.
80 81 82 83 84 85 |
# File 'lib/riak/crdt/inner_counter.rb', line 80 def self.update(increment) Operation::Update.new.tap do |op| op.value = increment op.type = :counter end end |
Instance Method Details
#batch {|batch_counter| ... } ⇒ Object
Perform multiple increments against this counter, and collapse them into a single operation.
64 65 66 67 68 69 70 |
# File 'lib/riak/crdt/inner_counter.rb', line 64 def batch batcher = BatchCounter.new yield batcher increment batcher.accumulator end |
#decrement(amount = 1) ⇒ Object
Decrement the counter. Opposite of increment.
55 56 57 |
# File 'lib/riak/crdt/inner_counter.rb', line 55 def decrement(amount = 1) increment -amount end |
#increment(amount = 1) ⇒ Object
Increment the counter.
48 49 50 |
# File 'lib/riak/crdt/inner_counter.rb', line 48 def increment(amount = 1) @parent.increment name, amount end |
#pretty_print(pp) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/riak/crdt/inner_counter.rb', line 72 def pretty_print(pp) pp.object_group self do pp.breakable pp.pp value end end |