Class: Riak::CRDT::TPNCounter
- Inherits:
-
Object
- Object
- Riak::CRDT::TPNCounter
- Defined in:
- lib/crdt/tpncounter.rb
Instance Attribute Summary collapse
-
#n ⇒ Object
Returns the value of attribute n.
-
#p ⇒ Object
Returns the value of attribute p.
Class Method Summary collapse
Instance Method Summary collapse
-
#decrement(transaction, value) ⇒ Object
Increment this actor’s negative transaction array, overwriting if the value exists.
- #has_transaction?(transaction) ⇒ Boolean
-
#increment(transaction, value) ⇒ Object
Increment this actor’s positive transaction array, overwriting if the value exists.
-
#initialize(options) ⇒ TPNCounter
constructor
Create a new Transaction PNCounter.
- #merge(other) ⇒ Object
- #to_json ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(options) ⇒ TPNCounter
Create a new Transaction PNCounter
13 14 15 16 |
# File 'lib/crdt/tpncounter.rb', line 13 def initialize() self.p = TGCounter.new() self.n = TGCounter.new() end |
Instance Attribute Details
#n ⇒ Object
Returns the value of attribute n.
5 6 7 |
# File 'lib/crdt/tpncounter.rb', line 5 def n @n end |
#p ⇒ Object
Returns the value of attribute p.
5 6 7 |
# File 'lib/crdt/tpncounter.rb', line 5 def p @p end |
Class Method Details
.from_json(json, options) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/crdt/tpncounter.rb', line 26 def self.from_json(json, ) h = JSON.parse json raise ArgumentError.new 'unexpected type field in JSON' unless h['type'] == 'TPNCounter' pnc = new() pnc.p = TGCounter.from_hash(h['p'], ) pnc.n = TGCounter.from_hash(h['n'], ) return pnc end |
Instance Method Details
#decrement(transaction, value) ⇒ Object
Increment this actor’s negative transaction array, overwriting if the value exists
47 48 49 |
# File 'lib/crdt/tpncounter.rb', line 47 def decrement(transaction, value) self.n.increment(transaction, value) end |
#has_transaction?(transaction) ⇒ Boolean
55 56 57 |
# File 'lib/crdt/tpncounter.rb', line 55 def has_transaction?(transaction) self.p.has_transaction?(transaction) || self.n.has_transaction?(transaction) end |
#increment(transaction, value) ⇒ Object
Increment this actor’s positive transaction array, overwriting if the value exists
40 41 42 |
# File 'lib/crdt/tpncounter.rb', line 40 def increment(transaction, value) self.p.increment(transaction, value) end |
#merge(other) ⇒ Object
59 60 61 62 |
# File 'lib/crdt/tpncounter.rb', line 59 def merge(other) self.p.merge(other.p) self.n.merge(other.n) end |
#to_json ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/crdt/tpncounter.rb', line 18 def to_json { type: 'TPNCounter', p: self.p.to_hash, n: self.n.to_hash }.to_json end |
#value ⇒ Object
51 52 53 |
# File 'lib/crdt/tpncounter.rb', line 51 def value self.p.value - self.n.value end |