Class: Riak::Crdt::GrowOnlySet
- Includes:
- Util::String
- Defined in:
- lib/riak/crdt/grow_only_set.rb
Overview
A distributed grow-only 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.
Direct Known Subclasses
Defined Under Namespace
Classes: BatchGrowOnlySet
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#add(element, options = {}) ⇒ Object
Add a String to the GrowOnlySet.
- #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 = {}) ⇒ GrowOnlySet
constructor
Create a grow-only 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
-
#to_a ⇒ Array
Cast this GrowOnlySet to a Ruby Array.
-
#vivify(value) {|batch_grow_only_set| ... } ⇒ Object
Yields a ‘BatchGrowOnlySet` to proxy multiple add operations into a single Riak update.
Methods included from Util::String
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 = {}) ⇒ GrowOnlySet
Create a grow-only 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/grow_only_set.rb', line 39 def initialize(bucket, key, bucket_type = nil, = {}) super(bucket, key, bucket_type || :gset, ) end |
Instance Method Details
#add(element, options = {}) ⇒ Object
Add a String to the Riak::Crdt::GrowOnlySet
100 101 102 |
# File 'lib/riak/crdt/grow_only_set.rb', line 100 def add(element, = {}) operate operation(:add, element), end |
#batch {|batcher| ... } ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/riak/crdt/grow_only_set.rb', line 54 def batch batcher = BatchGrowOnlySet.new self yield batcher operate batcher.operations end |
#empty? ⇒ Boolean
Check to see if this structure has any members.
84 85 86 |
# File 'lib/riak/crdt/grow_only_set.rb', line 84 def empty? members.empty? end |
#include?(candidate) ⇒ Boolean
Check to see if a given string is present in this data structure.
92 93 94 |
# File 'lib/riak/crdt/grow_only_set.rb', line 92 def include?(candidate) members.any? { |m| equal_bytes?(m, candidate) } end |
#members ⇒ ::Set Also known as: value
Gets the current set members from Riak if necessary, and return the stdlib ‘::Set` of them.
67 68 69 70 |
# File 'lib/riak/crdt/grow_only_set.rb', line 67 def members reload if dirty? @members end |
#pretty_print(pp) ⇒ Object
104 105 106 107 108 109 |
# File 'lib/riak/crdt/grow_only_set.rb', line 104 def pretty_print(pp) super pp do pp.comma_breakable pp.pp to_a end end |
#to_a ⇒ Array
Cast this Riak::Crdt::GrowOnlySet to a Ruby Array.
77 78 79 |
# File 'lib/riak/crdt/grow_only_set.rb', line 77 def to_a members.to_a end |
#vivify(value) {|batch_grow_only_set| ... } ⇒ Object
Yields a ‘BatchGrowOnlySet` to proxy multiple add operations into a single Riak update. The `BatchGrowOnlySet` has the same methods as this Riak::Crdt::GrowOnlySet.
48 49 50 51 52 |
# File 'lib/riak/crdt/grow_only_set.rb', line 48 def vivify(value) value.each(&:freeze) @members = ::Set.new(value) @members.freeze end |