riak-client 2.2.0.pre1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +0 -2
- data/README.markdown +11 -7
- data/RELEASE_NOTES.md +29 -2
- data/Rakefile +5 -3
- data/lib/riak/bucket.rb +55 -23
- data/lib/riak/bucket_properties.rb +8 -1
- data/lib/riak/bucket_type.rb +29 -0
- data/lib/riak/bucket_typed/bucket.rb +15 -7
- data/lib/riak/client.rb +24 -8
- data/lib/riak/client/beefcake/bucket_properties_operator.rb +8 -8
- data/lib/riak/client/beefcake/crdt/set_loader.rb +1 -1
- data/lib/riak/client/beefcake/crdt_loader.rb +1 -1
- data/lib/riak/client/beefcake/crdt_operator.rb +9 -9
- data/lib/riak/client/beefcake/message_codes.rb +4 -0
- data/lib/riak/client/beefcake/message_overlay.rb +4 -0
- data/lib/riak/client/beefcake/messages.rb +35 -5
- data/lib/riak/client/beefcake/object_methods.rb +21 -13
- data/lib/riak/client/beefcake/protocol.rb +7 -7
- data/lib/riak/client/beefcake/socket.rb +2 -2
- data/lib/riak/client/beefcake_protobuffs_backend.rb +58 -33
- data/lib/riak/client/protobuffs_backend.rb +5 -5
- data/lib/riak/client/yokozuna.rb +3 -3
- data/lib/riak/core_ext/deep_dup.rb +1 -1
- data/lib/riak/counter.rb +10 -10
- data/lib/riak/crdt/base.rb +39 -21
- data/lib/riak/crdt/batch_counter.rb +5 -5
- data/lib/riak/crdt/batch_map.rb +2 -2
- data/lib/riak/crdt/counter.rb +7 -7
- data/lib/riak/crdt/inner_counter.rb +4 -4
- data/lib/riak/crdt/inner_flag.rb +3 -3
- data/lib/riak/crdt/inner_map.rb +1 -1
- data/lib/riak/crdt/inner_register.rb +1 -1
- data/lib/riak/crdt/inner_set.rb +5 -5
- data/lib/riak/crdt/map.rb +9 -9
- data/lib/riak/crdt/set.rb +10 -10
- data/lib/riak/crdt/typed_collection.rb +39 -36
- data/lib/riak/errors/base.rb +1 -1
- data/lib/riak/errors/crdt_error.rb +20 -0
- data/lib/riak/errors/search_error.rb +6 -0
- data/lib/riak/index_collection.rb +1 -1
- data/lib/riak/link.rb +5 -3
- data/lib/riak/locale/en.yml +5 -1
- data/lib/riak/map_reduce.rb +7 -7
- data/lib/riak/map_reduce/filter_builder.rb +2 -2
- data/lib/riak/map_reduce/phase.rb +2 -2
- data/lib/riak/preflist_item.rb +7 -0
- data/lib/riak/rcontent.rb +8 -8
- data/lib/riak/robject.rb +27 -14
- data/lib/riak/search.rb +1 -0
- data/lib/riak/search/index.rb +17 -3
- data/lib/riak/search/query.rb +14 -6
- data/lib/riak/search/result_collection.rb +56 -3
- data/lib/riak/search/result_document.rb +71 -1
- data/lib/riak/search/schema.rb +6 -6
- data/lib/riak/secondary_index.rb +20 -12
- data/lib/riak/serializers.rb +0 -1
- data/lib/riak/util/escape.rb +2 -2
- data/lib/riak/util/translation.rb +1 -2
- data/lib/riak/version.rb +1 -1
- data/lib/riak/walk_spec.rb +67 -32
- data/riak-client.gemspec +5 -4
- data/spec/integration/riak/bucket_types_spec.rb +35 -5
- data/spec/integration/riak/conflict_resolution_spec.rb +1 -1
- data/spec/integration/riak/counters_spec.rb +1 -1
- data/spec/integration/riak/crdt/configuration_spec.rb +37 -0
- data/spec/integration/riak/crdt_search_spec.rb +176 -0
- data/spec/integration/riak/crdt_spec.rb +9 -33
- data/spec/integration/riak/crdt_validation/map_spec.rb +4 -4
- data/spec/integration/riak/crdt_validation/set_spec.rb +13 -13
- data/spec/integration/riak/preflist_spec.rb +31 -0
- data/spec/integration/riak/protobuffs/interrupted_request_spec.rb +2 -2
- data/spec/integration/riak/protobuffs_backends_spec.rb +9 -2
- data/spec/integration/riak/search_spec.rb +3 -3
- data/spec/integration/riak/secondary_index_spec.rb +3 -3
- data/spec/integration/riak/security_spec.rb +7 -7
- data/spec/integration/yokozuna/queries_spec.rb +1 -1
- data/spec/riak/beefcake_protobuffs_backend/bucket_properties_operator_spec.rb +9 -9
- data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +9 -9
- data/spec/riak/beefcake_protobuffs_backend/protocol_spec.rb +5 -5
- data/spec/riak/beefcake_protobuffs_backend_spec.rb +8 -8
- data/spec/riak/bucket_properties_spec.rb +27 -6
- data/spec/riak/bucket_spec.rb +5 -5
- data/spec/riak/bucket_type_spec.rb +21 -5
- data/spec/riak/bucket_typed/bucket_spec.rb +62 -0
- data/spec/riak/client_spec.rb +36 -18
- data/spec/riak/counter_spec.rb +4 -4
- data/spec/riak/crdt/counter_spec.rb +2 -2
- data/spec/riak/crdt/inner_flag_spec.rb +2 -2
- data/spec/riak/crdt/inner_map_spec.rb +4 -4
- data/spec/riak/crdt/inner_register_spec.rb +1 -1
- data/spec/riak/crdt/map_spec.rb +4 -4
- data/spec/riak/crdt/shared_examples.rb +5 -5
- data/spec/riak/crdt/typed_collection_spec.rb +21 -21
- data/spec/riak/map_reduce/filter_builder_spec.rb +2 -2
- data/spec/riak/map_reduce/phase_spec.rb +4 -4
- data/spec/riak/map_reduce_spec.rb +60 -42
- data/spec/riak/multiget_spec.rb +2 -2
- data/spec/riak/robject_spec.rb +55 -14
- data/spec/riak/search/index_spec.rb +12 -2
- data/spec/riak/search/query_spec.rb +4 -4
- data/spec/riak/search/result_collection_spec.rb +6 -4
- data/spec/riak/search/result_document_spec.rb +52 -9
- data/spec/riak/search/schema_spec.rb +2 -2
- data/spec/riak/secondary_index_spec.rb +6 -6
- data/spec/riak/serializers_spec.rb +27 -10
- data/spec/riak/walk_spec_spec.rb +10 -6
- data/spec/spec_helper.rb +11 -2
- data/spec/support/crdt_search_config.rb +112 -0
- data/spec/support/crdt_search_fixtures.rb +42 -0
- data/spec/support/search_config.rb +7 -5
- data/spec/support/search_corpus_setup.rb +2 -2
- data/spec/support/test_client.rb +2 -2
- data/spec/support/unified_backend_examples.rb +5 -5
- data/spec/support/version_filter.rb +5 -3
- data/spec/support/wait_until.rb +9 -3
- metadata +36 -13
- data/spec/riak/bucket_typed/bucket.rb +0 -43
@@ -2,16 +2,16 @@ module Riak
|
|
2
2
|
module Crdt
|
3
3
|
class BatchCounter
|
4
4
|
attr_reader :accumulator
|
5
|
-
|
5
|
+
|
6
6
|
def initialize
|
7
7
|
@accumulator = 0
|
8
8
|
end
|
9
|
-
|
10
|
-
def increment(amount=1)
|
9
|
+
|
10
|
+
def increment(amount = 1)
|
11
11
|
@accumulator += amount
|
12
12
|
end
|
13
|
-
|
14
|
-
def decrement(amount=1)
|
13
|
+
|
14
|
+
def decrement(amount = 1)
|
15
15
|
increment -amount
|
16
16
|
end
|
17
17
|
end
|
data/lib/riak/crdt/batch_map.rb
CHANGED
@@ -4,7 +4,7 @@ module Riak
|
|
4
4
|
# Riak all at once.
|
5
5
|
class BatchMap
|
6
6
|
attr_reader :counters, :flags, :maps, :registers, :sets
|
7
|
-
|
7
|
+
|
8
8
|
# @api private
|
9
9
|
def initialize(parent)
|
10
10
|
@parent = parent
|
@@ -27,7 +27,7 @@ module Riak
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
private
|
32
32
|
def initialize_collections
|
33
33
|
@counters = @parent.counters.reparent self
|
data/lib/riak/crdt/counter.rb
CHANGED
@@ -19,10 +19,10 @@ module Riak
|
|
19
19
|
# @param [String] bucket_type The optional bucket type for this counter.
|
20
20
|
# The default is in `Crdt::Base::DEFAULT_BUCKET_TYPES[:counter]`.
|
21
21
|
# @param [Hash] options
|
22
|
-
def initialize(bucket, key, bucket_type=nil, options={})
|
22
|
+
def initialize(bucket, key, bucket_type = nil, options = {})
|
23
23
|
super(bucket, key, bucket_type || :counter, options)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
# The current value of the counter; hits the server if the value has
|
27
27
|
# not been fetched or if the counter has been incremented.
|
28
28
|
def value
|
@@ -34,7 +34,7 @@ module Riak
|
|
34
34
|
#
|
35
35
|
# @param [Integer] amount
|
36
36
|
# @param [Hash] options
|
37
|
-
def increment(amount=1, options={})
|
37
|
+
def increment(amount = 1, options = {})
|
38
38
|
operate operation(amount), options
|
39
39
|
end
|
40
40
|
|
@@ -46,16 +46,16 @@ module Riak
|
|
46
46
|
batcher = BatchCounter.new
|
47
47
|
|
48
48
|
yield batcher
|
49
|
-
|
49
|
+
|
50
50
|
increment batcher.accumulator
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
alias :to_i :value
|
54
54
|
|
55
55
|
# Decrement the counter.
|
56
56
|
#
|
57
57
|
# @param [Integer] amount
|
58
|
-
def decrement(amount=1)
|
58
|
+
def decrement(amount = 1)
|
59
59
|
increment -amount
|
60
60
|
end
|
61
61
|
|
@@ -65,7 +65,7 @@ module Riak
|
|
65
65
|
pp.text "value=#{value}"
|
66
66
|
end
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
private
|
70
70
|
def vivify(value)
|
71
71
|
@value = value
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Riak
|
2
2
|
module Crdt
|
3
|
-
# The {InnerCounter} lives inside a {Map}, or an {InnerMap} inside of a
|
3
|
+
# The {InnerCounter} lives inside a {Map}, or an {InnerMap} inside of a
|
4
4
|
# {Map}, and is accessed through a {TypedCollection}.
|
5
5
|
#
|
6
6
|
# Much like the {Riak::Crdt::Counter}, it provides an integer value that can
|
@@ -21,9 +21,9 @@ module Riak
|
|
21
21
|
#
|
22
22
|
# @api private
|
23
23
|
attr_reader :parent
|
24
|
-
|
24
|
+
|
25
25
|
# @api private
|
26
|
-
def initialize(parent, value=0)
|
26
|
+
def initialize(parent, value = 0)
|
27
27
|
@parent = parent
|
28
28
|
@value = value
|
29
29
|
end
|
@@ -54,7 +54,7 @@ module Riak
|
|
54
54
|
|
55
55
|
increment batcher.accumulator
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
def pretty_print(pp)
|
59
59
|
pp.object_group self do
|
60
60
|
pp.breakable
|
data/lib/riak/crdt/inner_flag.rb
CHANGED
@@ -6,15 +6,15 @@ module Riak
|
|
6
6
|
#
|
7
7
|
# @api private
|
8
8
|
class InnerFlag
|
9
|
-
def self.new(parent, value=false)
|
9
|
+
def self.new(parent, value = false)
|
10
10
|
ensure_boolean value
|
11
|
-
|
11
|
+
|
12
12
|
return value
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.update(value)
|
16
16
|
ensure_boolean value
|
17
|
-
|
17
|
+
|
18
18
|
Operation::Update.new.tap do |op|
|
19
19
|
op.value = value
|
20
20
|
op.type = :flag
|
data/lib/riak/crdt/inner_map.rb
CHANGED
data/lib/riak/crdt/inner_set.rb
CHANGED
@@ -4,14 +4,14 @@ module Riak
|
|
4
4
|
# a {Map} (or an {InnerMap} inside of a {Map}). It is usually accessed
|
5
5
|
# through a {TypedCollection}.
|
6
6
|
#
|
7
|
-
# Just like a {Riak::Crdt::Set}, it's a set of {String Strings} that can
|
7
|
+
# Just like a {Riak::Crdt::Set}, it's a set of {String Strings} that can
|
8
8
|
# be added to or removed from.
|
9
9
|
class InnerSet
|
10
10
|
# The name of this set inside a map.
|
11
11
|
#
|
12
12
|
# @api private
|
13
13
|
attr_accessor :name
|
14
|
-
|
14
|
+
|
15
15
|
# The {::Set} value of this {InnerSet}.
|
16
16
|
#
|
17
17
|
# @return [::Set] set value
|
@@ -24,13 +24,13 @@ module Riak
|
|
24
24
|
attr_reader :parent
|
25
25
|
|
26
26
|
# @api private
|
27
|
-
def initialize(parent, value=[])
|
27
|
+
def initialize(parent, value = [])
|
28
28
|
@parent = parent
|
29
29
|
frozen_value = value.to_a.tap{ |v| v.each(&:freeze) }
|
30
30
|
@value = ::Set.new frozen_value
|
31
31
|
@value.freeze
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
# Casts this {InnerSet} to an {Array}.
|
35
35
|
#
|
36
36
|
# @return [Array] an array of all the members of this set
|
@@ -68,7 +68,7 @@ module Riak
|
|
68
68
|
@parent.operate name, update(remove: element)
|
69
69
|
end
|
70
70
|
|
71
|
-
|
71
|
+
|
72
72
|
# Does the map containing this set have the context necessary to remove elements?
|
73
73
|
#
|
74
74
|
# @return [Boolean] if the set has a defined context
|
data/lib/riak/crdt/map.rb
CHANGED
@@ -16,10 +16,10 @@ module Riak
|
|
16
16
|
# * {InnerRegister}: a {String} value inside a map
|
17
17
|
# * {InnerCounter}: a {Riak::Crdt::Counter}, but inside a map
|
18
18
|
# * {InnerSet}: a {Riak::Crdt::Set}, but inside a map
|
19
|
-
#
|
19
|
+
#
|
20
20
|
class Map < Base
|
21
21
|
attr_reader :counters, :flags, :maps, :registers, :sets
|
22
|
-
|
22
|
+
|
23
23
|
# Create a map instance. The bucket type is determined by the first of
|
24
24
|
# these sources:
|
25
25
|
#
|
@@ -33,21 +33,21 @@ module Riak
|
|
33
33
|
# @param [String] bucket_type The optional bucket type for this map.
|
34
34
|
# The default is in `Crdt::Base::DEFAULT_BUCKET_TYPES[:map]`.
|
35
35
|
# @param options [Hash]
|
36
|
-
def initialize(bucket, key, bucket_type=nil, options={})
|
36
|
+
def initialize(bucket, key, bucket_type = nil, options = {})
|
37
37
|
super(bucket, key, bucket_type || :map, options)
|
38
38
|
|
39
39
|
if key
|
40
|
-
initialize_collections
|
40
|
+
initialize_collections
|
41
41
|
else
|
42
42
|
initialize_blank_collections
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
# Maps are frequently updated in batches. Use this method to get a
|
46
|
+
# Maps are frequently updated in batches. Use this method to get a
|
47
47
|
# {BatchMap} to turn multiple operations into a single Riak update
|
48
48
|
# request.
|
49
49
|
#
|
50
|
-
# @yieldparam batch_map [BatchMap] collects updates and other operations
|
50
|
+
# @yieldparam batch_map [BatchMap] collects updates and other operations
|
51
51
|
def batch(*args)
|
52
52
|
batch_map = BatchMap.new self
|
53
53
|
|
@@ -58,7 +58,7 @@ module Riak
|
|
58
58
|
|
59
59
|
# This method *for internal use only* is used to collect oprations from
|
60
60
|
# disparate sources to provide a user-friendly API.
|
61
|
-
#
|
61
|
+
#
|
62
62
|
# @api private
|
63
63
|
def operate(operation, *args)
|
64
64
|
batch *args do |m|
|
@@ -83,7 +83,7 @@ module Riak
|
|
83
83
|
end
|
84
84
|
|
85
85
|
alias :value :to_value_h
|
86
|
-
|
86
|
+
|
87
87
|
private
|
88
88
|
def vivify(data)
|
89
89
|
@counters = TypedCollection.new InnerCounter, self, data[:counters]
|
@@ -93,7 +93,7 @@ module Riak
|
|
93
93
|
@sets = TypedCollection.new InnerSet, self, data[:sets]
|
94
94
|
end
|
95
95
|
|
96
|
-
def initialize_collections(data={})
|
96
|
+
def initialize_collections(data = {})
|
97
97
|
reload if dirty?
|
98
98
|
end
|
99
99
|
|
data/lib/riak/crdt/set.rb
CHANGED
@@ -6,7 +6,7 @@ module Riak
|
|
6
6
|
# Uses the Ruby standard library `::Set` frequently, so the full class names will
|
7
7
|
# be used frequently.
|
8
8
|
class Set < Base
|
9
|
-
|
9
|
+
|
10
10
|
# Create a set instance. The bucket type is determined by the first of
|
11
11
|
# these sources:
|
12
12
|
#
|
@@ -19,12 +19,12 @@ module Riak
|
|
19
19
|
# Riak assign a key.
|
20
20
|
# @param [String] bucket_type The optional bucket type for this set.
|
21
21
|
# @param options [Hash]
|
22
|
-
def initialize(bucket, key, bucket_type=nil, options={})
|
22
|
+
def initialize(bucket, key, bucket_type = nil, options = {})
|
23
23
|
super(bucket, key, bucket_type || :set, options)
|
24
24
|
end
|
25
25
|
|
26
26
|
# Yields a `BatchSet` to proxy multiple set operations into a single
|
27
|
-
# Riak update. The `BatchSet` has the same methods as this
|
27
|
+
# Riak update. The `BatchSet` has the same methods as this
|
28
28
|
# {Riak::Crdt::Set}.
|
29
29
|
#
|
30
30
|
# @yieldparam batch_set [BatchSet] collects set operations
|
@@ -38,7 +38,7 @@ module Riak
|
|
38
38
|
batcher = BatchSet.new self
|
39
39
|
|
40
40
|
yield batcher
|
41
|
-
|
41
|
+
|
42
42
|
operate batcher.operations
|
43
43
|
end
|
44
44
|
|
@@ -53,7 +53,7 @@ module Riak
|
|
53
53
|
end
|
54
54
|
|
55
55
|
alias :value :members
|
56
|
-
|
56
|
+
|
57
57
|
# Cast this {Riak::Crdt::Set} to a Ruby {Array}.
|
58
58
|
#
|
59
59
|
# @return [Array] array of set members
|
@@ -67,7 +67,7 @@ module Riak
|
|
67
67
|
def empty?
|
68
68
|
members.empty?
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
# Check to see if a given string is present in this data structure.
|
72
72
|
#
|
73
73
|
# @param [String] candidate string to check for inclusion in this structure
|
@@ -80,7 +80,7 @@ module Riak
|
|
80
80
|
#
|
81
81
|
# @param [String] element the element to add to the set
|
82
82
|
# @param [Hash] options
|
83
|
-
def add(element, options={})
|
83
|
+
def add(element, options = {})
|
84
84
|
operate operation(:add, element), options
|
85
85
|
end
|
86
86
|
|
@@ -88,13 +88,13 @@ module Riak
|
|
88
88
|
#
|
89
89
|
# @param [String] element to remove from the set
|
90
90
|
# @param [Hash] options
|
91
|
-
def remove(element, options={})
|
91
|
+
def remove(element, options = {})
|
92
92
|
raise CrdtError::SetRemovalWithoutContextError unless context?
|
93
93
|
operate operation(:remove, element), options
|
94
94
|
end
|
95
95
|
|
96
96
|
alias :delete :remove
|
97
|
-
|
97
|
+
|
98
98
|
def pretty_print(pp)
|
99
99
|
super pp do
|
100
100
|
pp.comma_breakable
|
@@ -120,7 +120,7 @@ module Riak
|
|
120
120
|
@adds = ::Set.new
|
121
121
|
@removes = ::Set.new
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
def add(element)
|
125
125
|
@adds.add element
|
126
126
|
end
|
@@ -2,28 +2,17 @@ module Riak
|
|
2
2
|
module Crdt
|
3
3
|
# A collection of elements of a given type inside a {Map}.
|
4
4
|
class TypedCollection
|
5
|
-
|
6
5
|
ALREADY_WRAPPED = ::Set.new [InnerCounter, InnerFlag, InnerMap]
|
7
6
|
NEEDS_NAME = ::Set.new [InnerCounter, InnerSet, InnerMap]
|
8
7
|
INITIALIZE_NIL = ::Set.new [InnerRegister]
|
9
|
-
|
8
|
+
|
10
9
|
# @api private
|
11
|
-
def initialize(type, parent, contents={})
|
10
|
+
def initialize(type, parent, contents = {})
|
12
11
|
@type = type
|
13
12
|
@parent = parent
|
14
13
|
contents = {} if contents.nil?
|
15
14
|
stringified_contents = contents.stringify_keys
|
16
|
-
@contents = stringified_contents
|
17
|
-
contents.tap do |c|
|
18
|
-
content = stringified_contents[key]
|
19
|
-
if ALREADY_WRAPPED.include? content.class
|
20
|
-
c[key] = content
|
21
|
-
else
|
22
|
-
c[key] = @type.new self, content
|
23
|
-
end
|
24
|
-
c[key].name = key if needs_name?
|
25
|
-
end
|
26
|
-
end
|
15
|
+
@contents = materialize_contents stringified_contents
|
27
16
|
end
|
28
17
|
|
29
18
|
def pretty_print(pp)
|
@@ -31,15 +20,15 @@ module Riak
|
|
31
20
|
pp.breakable
|
32
21
|
pp.text inspect_name
|
33
22
|
pp.comma_breakable
|
34
|
-
pp.text
|
23
|
+
pp.text 'parent='
|
35
24
|
@parent.pretty_print_cycle(pp)
|
36
25
|
pp.comma_breakable
|
37
|
-
pp.text
|
26
|
+
pp.text 'contents='
|
38
27
|
pp.pp @contents
|
39
28
|
end
|
40
29
|
# buf = []
|
41
30
|
# buf << inspect_name
|
42
|
-
# buf <<
|
31
|
+
# buf <<
|
43
32
|
# buf << "contents={#{inspect_contents}}"
|
44
33
|
# "#<#{self.class.name} #{buf.join ' '}>"
|
45
34
|
end
|
@@ -55,8 +44,8 @@ module Riak
|
|
55
44
|
"contains=#{content_name}"
|
56
45
|
end
|
57
46
|
|
58
|
-
def pretty_print_contents(
|
59
|
-
@contents.map do |k,v|
|
47
|
+
def pretty_print_contents(_pp)
|
48
|
+
@contents.map do |k, v|
|
60
49
|
"#{k}=>#{v.inspect}"
|
61
50
|
end.join ', '
|
62
51
|
end
|
@@ -67,11 +56,11 @@ module Riak
|
|
67
56
|
|
68
57
|
# @api private
|
69
58
|
def reparent(new_parent)
|
70
|
-
|
71
|
-
|
72
|
-
|
59
|
+
self.class.new(@type,
|
60
|
+
new_parent,
|
61
|
+
@contents)
|
73
62
|
end
|
74
|
-
|
63
|
+
|
75
64
|
# Check if a value for a given key exists in this map.
|
76
65
|
#
|
77
66
|
# @param [String] key the key to check for
|
@@ -79,7 +68,7 @@ module Riak
|
|
79
68
|
def include?(key)
|
80
69
|
@contents.include? normalize_key(key)
|
81
70
|
end
|
82
|
-
|
71
|
+
|
83
72
|
# Get the value for a given key
|
84
73
|
#
|
85
74
|
# @param [String] key the key to get the value for
|
@@ -93,15 +82,15 @@ module Riak
|
|
93
82
|
end
|
94
83
|
|
95
84
|
return nil if initialize_nil?
|
96
|
-
|
85
|
+
|
97
86
|
new_instance = @type.new self
|
98
87
|
new_instance.name = key if needs_name?
|
99
88
|
|
100
|
-
|
89
|
+
new_instance
|
101
90
|
end
|
102
91
|
|
103
92
|
# Set the value for a given key. Operation of this method
|
104
|
-
# is only defined for {InnerCounter}, {InnerRegister}, and
|
93
|
+
# is only defined for {InnerCounter}, {InnerRegister}, and
|
105
94
|
# {InnerFlag} types.
|
106
95
|
#
|
107
96
|
# @param [String] key the key to set a new value for
|
@@ -117,11 +106,11 @@ module Riak
|
|
117
106
|
|
118
107
|
@contents[key] = @type.new self, value
|
119
108
|
@contents[key].name = key if needs_name?
|
120
|
-
|
109
|
+
|
121
110
|
result
|
122
111
|
end
|
123
|
-
|
124
|
-
|
112
|
+
|
113
|
+
alias_method :increment, :[]=
|
125
114
|
|
126
115
|
# Remove the entry from the map.
|
127
116
|
#
|
@@ -139,20 +128,19 @@ module Riak
|
|
139
128
|
# @api private
|
140
129
|
def operate(key, inner_operation)
|
141
130
|
key = normalize_key key
|
142
|
-
|
131
|
+
|
143
132
|
inner_operation.name = key
|
144
|
-
|
133
|
+
|
145
134
|
@parent.operate inner_operation
|
146
135
|
end
|
147
|
-
|
148
|
-
|
136
|
+
|
149
137
|
# Does this set have the context necessary to remove elements?
|
150
138
|
#
|
151
139
|
# @return [Boolean] if the set has a defined context
|
152
140
|
def context?
|
153
141
|
!!@parent.context?
|
154
142
|
end
|
155
|
-
|
143
|
+
|
156
144
|
def to_value_h
|
157
145
|
return @contents unless NEEDS_NAME.include? @type
|
158
146
|
|
@@ -162,6 +150,7 @@ module Riak
|
|
162
150
|
end
|
163
151
|
|
164
152
|
private
|
153
|
+
|
165
154
|
def normalize_key(unnormalized_key)
|
166
155
|
unnormalized_key.to_s
|
167
156
|
end
|
@@ -169,10 +158,24 @@ module Riak
|
|
169
158
|
def initialize_nil?
|
170
159
|
INITIALIZE_NIL.include? @type
|
171
160
|
end
|
172
|
-
|
161
|
+
|
173
162
|
def needs_name?
|
174
163
|
NEEDS_NAME.include? @type
|
175
164
|
end
|
165
|
+
|
166
|
+
def materialize_contents(stringified_contents)
|
167
|
+
stringified_contents.keys.inject(Hash.new) do |new_contents, key|
|
168
|
+
new_contents.tap do |c|
|
169
|
+
content = stringified_contents[key]
|
170
|
+
if ALREADY_WRAPPED.include? content.class
|
171
|
+
c[key] = content
|
172
|
+
else
|
173
|
+
c[key] = @type.new self, content
|
174
|
+
end
|
175
|
+
c[key].name = key if needs_name?
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
176
179
|
end
|
177
180
|
end
|
178
181
|
end
|