Module: Meangirls
- Defined in:
- lib/meangirls.rb,
lib/meangirls/version.rb
Defined Under Namespace
Classes: CRDT, Counter, DeleteNotAllowed, GCounter, LWWSet, ORSet, ReinsertNotAllowed, Set, TwoPhaseSet
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
-
.node ⇒ Object
The default node name.
-
.node=(node) ⇒ Object
Set the default node name.
-
.parse(s) ⇒ Object
Transforms a JSON data structure into a CRDT datatype.
-
.tag ⇒ Object
Return a pseudounique tag.
-
.timestamp ⇒ Object
An ISO8601 time as close to the current time as possible, with the additional constraint that successive calls to this method will return monotonically increasing values.
Class Method Details
.node ⇒ Object
The default node name.
31 32 33 |
# File 'lib/meangirls.rb', line 31 def node @node ||= Socket.gethostname end |
.node=(node) ⇒ Object
Set the default node name.
37 38 39 |
# File 'lib/meangirls.rb', line 37 def node=(node) @node = node end |
.parse(s) ⇒ Object
Transforms a JSON data structure into a CRDT datatype.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/meangirls.rb', line 14 def parse(s) case s['type'] when '2p-set' TwoPhaseSet.new s when 'lww-set' LWWSet.new s when 'or-set' ORSet.new s when 'g-counter' GCounter.new s else raise ArgumentError, "unknown type #{s['type']}" end end |
.tag ⇒ Object
Return a pseudounique tag.
43 44 45 |
# File 'lib/meangirls.rb', line 43 def tag SecureRandom.urlsafe_base64 end |
.timestamp ⇒ Object
An ISO8601 time as close to the current time as possible, with the additional constraint that successive calls to this method will return monotonically increasing values.
TODO: fold counter inside of time fraction
53 54 55 56 |
# File 'lib/meangirls.rb', line 53 def @i ||= 0 "#{Time.now.utc.iso8601}.#{@i += 1}" end |