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.
27 28 29 30 31 32 |
# File 'lib/riak/crdt/inner_set.rb', line 27 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.
13 14 15 |
# File 'lib/riak/crdt/inner_set.rb', line 13 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.
24 25 26 |
# File 'lib/riak/crdt/inner_set.rb', line 24 def parent @parent end |
#value ⇒ ::Set (readonly) Also known as: members
The Set value of this Riak::Crdt::InnerSet.
18 19 20 |
# File 'lib/riak/crdt/inner_set.rb', line 18 def value @value end |
Class Method Details
Instance Method Details
#add(element) ⇒ Object
Add a String to the Riak::Crdt::InnerSet
59 60 61 |
# File 'lib/riak/crdt/inner_set.rb', line 59 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?
75 76 77 |
# File 'lib/riak/crdt/inner_set.rb', line 75 def context? @parent.context? end |
#empty? ⇒ Boolean
Check if this Riak::Crdt::InnerSet is empty.
44 45 46 |
# File 'lib/riak/crdt/inner_set.rb', line 44 def empty? value.empty? end |
#include?(element) ⇒ Boolean
Check if a given string is in this structure.
52 53 54 |
# File 'lib/riak/crdt/inner_set.rb', line 52 def include?(element) value.include? element end |
#pretty_print(pp) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/riak/crdt/inner_set.rb', line 79 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
66 67 68 69 |
# File 'lib/riak/crdt/inner_set.rb', line 66 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.
37 38 39 |
# File 'lib/riak/crdt/inner_set.rb', line 37 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.
87 88 89 90 91 92 |
# File 'lib/riak/crdt/inner_set.rb', line 87 def update(changes) Operation::Update.new.tap do |op| op.value = changes.symbolize_keys op.type = :set end end |