Class: Riak::Crdt::Set::BatchSet

Inherits:
Object
  • Object
show all
Defined in:
lib/riak/crdt/set.rb

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ BatchSet

Returns a new instance of BatchSet.



121
122
123
124
125
# File 'lib/riak/crdt/set.rb', line 121

def initialize(base)
  @base = base
  @adds = ::Set.new
  @removes = ::Set.new
end

Instance Method Details

#add(element) ⇒ Object



127
128
129
# File 'lib/riak/crdt/set.rb', line 127

def add(element)
  @adds.add element
end

#context?Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/riak/crdt/set.rb', line 146

def context?
  @base.context?
end

#empty?Boolean

Returns:

  • (Boolean)


142
143
144
# File 'lib/riak/crdt/set.rb', line 142

def empty?
  members.empty?
end

#include?(element) ⇒ Boolean

Returns:

  • (Boolean)


138
139
140
# File 'lib/riak/crdt/set.rb', line 138

def include?(element)
  members.include? element
end

#membersObject Also known as: value



154
155
156
# File 'lib/riak/crdt/set.rb', line 154

def members
  (@base + @adds).subtract @removes
end

#operationsObject



160
161
162
163
164
165
# File 'lib/riak/crdt/set.rb', line 160

def operations
  Operation::Update.new.tap do |op|
    op.type = :set
    op.value = {add: @adds.to_a, remove: @removes.to_a}
  end
end

#remove(element) ⇒ Object Also known as: delete



131
132
133
134
# File 'lib/riak/crdt/set.rb', line 131

def remove(element)
  raise CrdtError::SetRemovalWithoutContextError.new unless context?
  @removes.add element
end

#to_aObject



150
151
152
# File 'lib/riak/crdt/set.rb', line 150

def to_a
  members.to_a
end