Class: Riak::Crdt::InnerSet
Overview
Instance Attribute Summary collapse
-
#name ⇒ Object
private
The name of this set inside a map.
-
#parent ⇒ Object
readonly
private
The parent of this counter.
- #value ⇒ ::Set (also: #members) readonly
Class Method Summary collapse
- .delete ⇒ Object private
Instance Method Summary collapse
- #add(element) ⇒ Object
-
#context? ⇒ Boolean
Does the map containing this set have the context necessary to remove elements?.
-
#empty? ⇒ Boolean
Check if this InnerSet is empty.
-
#include?(element) ⇒ Boolean
Check if a given string is in this structure.
-
#initialize(parent, value = []) ⇒ InnerSet
constructor
private
A new instance of InnerSet.
- #pretty_print(pp) ⇒ Object
-
#remove(element) ⇒ Object
Remove a String from this set.
- #to_a ⇒ Array
- #update(changes) ⇒ Object private
Constructor Details
#initialize(parent, value = []) ⇒ InnerSet
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 InnerSet.
41 42 43 44 45 46 |
# File 'lib/riak/crdt/inner_set.rb', line 41 def initialize(parent, value = []) @parent = parent frozen_value = value.to_a.tap{ |v| v.each(&:freeze) } @value = ::Set.new frozen_value @value.freeze 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 set inside a map.
27 28 29 |
# File 'lib/riak/crdt/inner_set.rb', line 27 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.
38 39 40 |
# File 'lib/riak/crdt/inner_set.rb', line 38 def parent @parent end |
#value ⇒ ::Set (readonly) Also known as: members
The Set value of this Riak::Crdt::InnerSet.
32 33 34 |
# File 'lib/riak/crdt/inner_set.rb', line 32 def value @value end |
Class Method Details
Instance Method Details
#add(element) ⇒ Object
Add a String to the Riak::Crdt::InnerSet
73 74 75 |
# File 'lib/riak/crdt/inner_set.rb', line 73 def add(element) @parent.operate name, update(add: element) end |
#context? ⇒ Boolean
Does the map containing this set have the context necessary to remove elements?
89 90 91 |
# File 'lib/riak/crdt/inner_set.rb', line 89 def context? @parent.context? end |
#empty? ⇒ Boolean
Check if this Riak::Crdt::InnerSet is empty.
58 59 60 |
# File 'lib/riak/crdt/inner_set.rb', line 58 def empty? value.empty? end |
#include?(element) ⇒ Boolean
Check if a given string is in this structure.
66 67 68 |
# File 'lib/riak/crdt/inner_set.rb', line 66 def include?(element) value.include? element end |
#pretty_print(pp) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/riak/crdt/inner_set.rb', line 93 def pretty_print(pp) pp.object_group self do pp.breakable pp.pp to_a end end |
#remove(element) ⇒ Object
Remove a String from this set
80 81 82 83 |
# File 'lib/riak/crdt/inner_set.rb', line 80 def remove(element) raise CrdtError::SetRemovalWithoutContextError unless context? @parent.operate name, update(remove: element) end |
#to_a ⇒ Array
Casts this Riak::Crdt::InnerSet to an Array.
51 52 53 |
# File 'lib/riak/crdt/inner_set.rb', line 51 def to_a value.to_a end |
#update(changes) ⇒ 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.
101 102 103 104 105 106 |
# File 'lib/riak/crdt/inner_set.rb', line 101 def update(changes) Operation::Update.new.tap do |op| op.value = changes.symbolize_keys op.type = :set end end |