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.
26 27 28 29 |
# File 'lib/riak/crdt/inner_counter.rb', line 26 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.
12 13 14 |
# File 'lib/riak/crdt/inner_counter.rb', line 12 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.
23 24 25 |
# File 'lib/riak/crdt/inner_counter.rb', line 23 def parent @parent end |
#value ⇒ Integer (readonly) Also known as: to_i
The value of this counter.
17 18 19 |
# File 'lib/riak/crdt/inner_counter.rb', line 17 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.
74 75 76 77 78 |
# File 'lib/riak/crdt/inner_counter.rb', line 74 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.
66 67 68 69 70 71 |
# 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 |
Instance Method Details
#batch {|batch_counter| ... } ⇒ Object
Perform multiple increments against this counter, and collapse them into a single operation.
50 51 52 53 54 55 56 |
# File 'lib/riak/crdt/inner_counter.rb', line 50 def batch batcher = BatchCounter.new yield batcher increment batcher.accumulator end |
#decrement(amount = 1) ⇒ Object
Decrement the counter. Opposite of increment.
41 42 43 |
# File 'lib/riak/crdt/inner_counter.rb', line 41 def decrement(amount = 1) increment -amount end |
#increment(amount = 1) ⇒ Object
Increment the counter.
34 35 36 |
# File 'lib/riak/crdt/inner_counter.rb', line 34 def increment(amount = 1) @parent.increment name, amount end |
#pretty_print(pp) ⇒ Object
58 59 60 61 62 63 |
# 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 |