Class: Riak::Crdt::Set
Overview
A distributed set containing strings, using the Riak 2 Data Types feature.
Uses the Ruby standard library ‘::Set` frequently, so the full class names will be used frequently.
Defined Under Namespace
Classes: BatchSet
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #add(element, options = {}) ⇒ Object
- #batch {|batcher| ... } ⇒ Object
-
#empty? ⇒ Boolean
Check to see if this structure has any members.
-
#include?(candidate) ⇒ Boolean
Check to see if a given string is present in this data structure.
-
#initialize(bucket, key, bucket_type = nil, options = {}) ⇒ Set
constructor
Create a set instance.
-
#members ⇒ ::Set
(also: #value)
Gets the current set members from Riak if necessary, and return the stdlib ‘::Set` of them.
- #pretty_print(pp) ⇒ Object
- #remove(element, options = {}) ⇒ Object (also: #delete)
- #to_a ⇒ Array
Methods inherited from Base
#==, #context?, #dirty?, #inspect_name, #pretty_print_cycle, #reload
Methods included from Util::Translation
Constructor Details
#initialize(bucket, key, bucket_type = nil, options = {}) ⇒ Set
Create a set instance. The bucket type is determined by the first of these sources:
-
The ‘bucket_type` String argument
-
A BucketTyped::Bucket as the ‘bucket` argument
-
The ‘Crdt::Base::DEFAULT_BUCKET_TYPES` entry
22 23 24 |
# File 'lib/riak/crdt/set.rb', line 22 def initialize(bucket, key, bucket_type = nil, = {}) super(bucket, key, bucket_type || :set, ) end |
Instance Method Details
#add(element, options = {}) ⇒ Object
Add a String to the Riak::Crdt::Set
83 84 85 |
# File 'lib/riak/crdt/set.rb', line 83 def add(element, = {}) operate operation(:add, element), end |
#batch {|batcher| ... } ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/riak/crdt/set.rb', line 37 def batch batcher = BatchSet.new self yield batcher operate batcher.operations end |
#empty? ⇒ Boolean
Check to see if this structure has any members.
67 68 69 |
# File 'lib/riak/crdt/set.rb', line 67 def empty? members.empty? end |
#include?(candidate) ⇒ Boolean
Check to see if a given string is present in this data structure.
75 76 77 |
# File 'lib/riak/crdt/set.rb', line 75 def include?(candidate) members.include?(candidate) end |
#members ⇒ ::Set Also known as: value
Gets the current set members from Riak if necessary, and return the stdlib ‘::Set` of them.
50 51 52 53 |
# File 'lib/riak/crdt/set.rb', line 50 def members reload if dirty? @members end |
#pretty_print(pp) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/riak/crdt/set.rb', line 98 def pretty_print(pp) super pp do pp.comma_breakable pp.pp to_a end end |
#remove(element, options = {}) ⇒ Object Also known as: delete
Remove a String from the Riak::Crdt::Set
91 92 93 94 |
# File 'lib/riak/crdt/set.rb', line 91 def remove(element, = {}) raise CrdtError::SetRemovalWithoutContextError unless context? operate operation(:remove, element), end |
#to_a ⇒ Array
Cast this Riak::Crdt::Set to a Ruby Array.
60 61 62 |
# File 'lib/riak/crdt/set.rb', line 60 def to_a members.to_a end |