class Riak::Crdt::InnerSet
The {InnerSet} is similar to a {Riak::Crdt::Set}, except it is part of a {Map} (or an {InnerMap} inside of a {Map}). It is usually accessed through a {TypedCollection}.
Just like a {Riak::Crdt::Set}, it’s a set of {String Strings} that can be added to or removed from.
Attributes
The {::Set} value of this {InnerSet}.
@return [::Set] set value
The name of this set inside a map.
@api private
The parent of this counter.
@api private
The {::Set} value of this {InnerSet}.
@return [::Set] set value
Public Class Methods
@api private
# File lib/riak/crdt/inner_set.rb, line 95 def self.delete Operation::Delete.new.tap do |op| op.type = :set end end
@api private
# 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
Public Instance Methods
Add a {String} to the {InnerSet}
@param [String] element the element to add
# File lib/riak/crdt/inner_set.rb, line 59 def add(element) @parent.operate name, update(add: element) end
Does the map containing this set have the context necessary to remove elements?
@return [Boolean] if the set has a defined context
# File lib/riak/crdt/inner_set.rb, line 75 def context? @parent.context? end
Check if this {InnerSet} is empty.
@return [Boolean} whether this structure is empty or not
# File lib/riak/crdt/inner_set.rb, line 44 def empty? value.empty? end
Check if a given string is in this structure.
@param [String] element candidate string to check for inclusion @return [Boolean] whether the candidate is in this set or not
# File lib/riak/crdt/inner_set.rb, line 52 def include?(element) value.include? element end
# 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 a {String} from this set
@param [String] element the element to remove
# File lib/riak/crdt/inner_set.rb, line 66 def remove(element) raise CrdtError::SetRemovalWithoutContextError unless context? @parent.operate name, update(remove: element) end
Casts this {InnerSet} to an {Array}.
@return [Array] an array of all the members of this set
# File lib/riak/crdt/inner_set.rb, line 37 def to_a value.to_a end
@api private
# 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