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



118
119
120
121
122
# File 'lib/riak/crdt/set.rb', line 118

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

Instance Method Details

#add(element) ⇒ Object



124
125
126
# File 'lib/riak/crdt/set.rb', line 124

def add(element)
  @adds.add element
end

#context?Boolean



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

def context?
  @base.context?
end

#empty?Boolean



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

def empty?
  members.empty?
end

#include?(element) ⇒ Boolean



135
136
137
# File 'lib/riak/crdt/set.rb', line 135

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

#membersObject Also known as: value



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

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

#operationsObject



157
158
159
160
161
162
# File 'lib/riak/crdt/set.rb', line 157

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



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

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

#to_aObject



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

def to_a
  members.to_a
end