Class: Riak::Crdt::Map
Overview
A distributed map of multiple fields, such as counters, flags, registers, sets, and, recursively, other maps, using the Riak 2 Data Types feature.
Maps are complex, and the implementation is spread across many classes. You're looking at the top-level Map class, but there are also others that are also responsible for how maps work:
- InnerMap: used for maps that live inside other maps
- BatchMap: proxies multiple operations into a single Riak update request
- TypedCollection: a collection of members of a single map, similar to a Ruby Hash
- InnerFlag: a boolean value inside a map
- InnerRegister: a String value inside a map
- InnerCounter: a Counter, but inside a map
- InnerSet: a Set, but inside a map
Instance Attribute Summary collapse
-
#counters ⇒ Object
readonly
Returns the value of attribute counters.
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#maps ⇒ Object
readonly
Returns the value of attribute maps.
-
#registers ⇒ Object
readonly
Returns the value of attribute registers.
-
#sets ⇒ Object
readonly
Returns the value of attribute sets.
Attributes inherited from Base
Instance Method Summary collapse
-
#batch(*args) {|batch_map| ... } ⇒ Object
Maps are frequently updated in batches.
-
#initialize(bucket, key, bucket_type = nil, options = {}) ⇒ Map
constructor
Create a map instance.
-
#operate(operation, *args) ⇒ Object
private
This method for internal use only is used to collect oprations from disparate sources to provide a user-friendly API.
- #pretty_print(pp) ⇒ Object
- #to_value_h ⇒ Object (also: #value)
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 = {}) ⇒ Map
Create a map instance. The bucket type is determined by the first of these sources:
- The
bucket_typeString argument - A BucketTyped::Bucket as the
bucketargument - The
Crdt::Base::DEFAULT_BUCKET_TYPES[:map]entry
35 36 37 38 39 40 41 42 43 |
# File 'lib/riak/crdt/map.rb', line 35 def initialize(bucket, key, bucket_type = nil, = {}) super(bucket, key, bucket_type || :map, ) if key initialize_collections else initialize_blank_collections end end |
Instance Attribute Details
#counters ⇒ Object (readonly)
Returns the value of attribute counters.
20 21 22 |
# File 'lib/riak/crdt/map.rb', line 20 def counters @counters end |
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
20 21 22 |
# File 'lib/riak/crdt/map.rb', line 20 def flags @flags end |
#maps ⇒ Object (readonly)
Returns the value of attribute maps.
20 21 22 |
# File 'lib/riak/crdt/map.rb', line 20 def maps @maps end |
#registers ⇒ Object (readonly)
Returns the value of attribute registers.
20 21 22 |
# File 'lib/riak/crdt/map.rb', line 20 def registers @registers end |
#sets ⇒ Object (readonly)
Returns the value of attribute sets.
20 21 22 |
# File 'lib/riak/crdt/map.rb', line 20 def sets @sets end |
Instance Method Details
#batch(*args) {|batch_map| ... } ⇒ Object
Maps are frequently updated in batches. Use this method to get a BatchMap to turn multiple operations into a single Riak update request.
50 51 52 53 54 55 56 |
# File 'lib/riak/crdt/map.rb', line 50 def batch(*args) batch_map = BatchMap.new self yield batch_map write_operations batch_map.operations, *args end |
#operate(operation, *args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method for internal use only is used to collect oprations from disparate sources to provide a user-friendly API.
62 63 64 65 66 |
# File 'lib/riak/crdt/map.rb', line 62 def operate(operation, *args) batch *args do |m| m.operate operation end end |
#pretty_print(pp) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/riak/crdt/map.rb', line 68 def pretty_print(pp) super pp do %w{counters flags maps registers sets}.each do |h| pp.comma_breakable pp.text "#{h}=" pp.pp send h end end end |
#to_value_h ⇒ Object Also known as: value
78 79 80 81 82 |
# File 'lib/riak/crdt/map.rb', line 78 def to_value_h %w{counters flags maps registers sets}.map do |k| [k, send(k).to_value_h] end.to_h end |