Class: Riak::Crdt::Set
- Inherits:
-
GrowOnlySet
- Object
- Base
- GrowOnlySet
- Riak::Crdt::Set
- Includes:
- Util::String
- Defined in:
- lib/riak/crdt/set.rb
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
-
#initialize(bucket, key, bucket_type = nil, options = {}) ⇒ Set
constructor
Create a set instance.
- #remove(element, options = {}) ⇒ Object (also: #delete)
- #to_a ⇒ Array
-
#vivify(value) {|batch_set| ... } ⇒ Object
Yields a ‘BatchSet` to proxy multiple set operations into a single Riak update.
Methods included from Util::String
Methods inherited from GrowOnlySet
#empty?, #include?, #members, #pretty_print
Methods inherited from Base
#==, #context?, #dirty?, #inspect_name, #pretty_print, #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
39 40 41 |
# File 'lib/riak/crdt/set.rb', line 39 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
73 74 75 |
# File 'lib/riak/crdt/set.rb', line 73 def add(element, = {}) operate operation(:add, element), end |
#batch {|batcher| ... } ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/riak/crdt/set.rb', line 54 def batch batcher = BatchSet.new self yield batcher operate batcher.operations end |
#remove(element, options = {}) ⇒ Object Also known as: delete
Remove a String from the Riak::Crdt::Set
81 82 83 84 |
# File 'lib/riak/crdt/set.rb', line 81 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.
65 66 67 |
# File 'lib/riak/crdt/set.rb', line 65 def to_a super.to_a end |
#vivify(value) {|batch_set| ... } ⇒ Object
Yields a ‘BatchSet` to proxy multiple set operations into a single Riak update. The `BatchSet` has the same methods as this Riak::Crdt::Set.
48 49 50 51 52 |
# File 'lib/riak/crdt/set.rb', line 48 def vivify(value) value.each(&:freeze) @members = ::Set.new(value) @members.freeze end |