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

members[R]

The {::Set} value of this {InnerSet}.

@return [::Set] set value

name[RW]

The name of this set inside a map.

@api private

parent[R]

The parent of this counter.

@api private

value[R]

The {::Set} value of this {InnerSet}.

@return [::Set] set value

Public Class Methods

delete() click to toggle source

@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
new(parent, value = []) click to toggle source

@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(element) click to toggle source

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
context?() click to toggle source

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
empty?() click to toggle source

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
include?(element) click to toggle source

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
pretty_print(pp) click to toggle source
# 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) click to toggle source

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
to_a() click to toggle source

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
update(changes) click to toggle source

@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