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.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +0 -2
  4. data/README.markdown +11 -7
  5. data/RELEASE_NOTES.md +29 -2
  6. data/Rakefile +5 -3
  7. data/lib/riak/bucket.rb +55 -23
  8. data/lib/riak/bucket_properties.rb +8 -1
  9. data/lib/riak/bucket_type.rb +29 -0
  10. data/lib/riak/bucket_typed/bucket.rb +15 -7
  11. data/lib/riak/client.rb +24 -8
  12. data/lib/riak/client/beefcake/bucket_properties_operator.rb +8 -8
  13. data/lib/riak/client/beefcake/crdt/set_loader.rb +1 -1
  14. data/lib/riak/client/beefcake/crdt_loader.rb +1 -1
  15. data/lib/riak/client/beefcake/crdt_operator.rb +9 -9
  16. data/lib/riak/client/beefcake/message_codes.rb +4 -0
  17. data/lib/riak/client/beefcake/message_overlay.rb +4 -0
  18. data/lib/riak/client/beefcake/messages.rb +35 -5
  19. data/lib/riak/client/beefcake/object_methods.rb +21 -13
  20. data/lib/riak/client/beefcake/protocol.rb +7 -7
  21. data/lib/riak/client/beefcake/socket.rb +2 -2
  22. data/lib/riak/client/beefcake_protobuffs_backend.rb +58 -33
  23. data/lib/riak/client/protobuffs_backend.rb +5 -5
  24. data/lib/riak/client/yokozuna.rb +3 -3
  25. data/lib/riak/core_ext/deep_dup.rb +1 -1
  26. data/lib/riak/counter.rb +10 -10
  27. data/lib/riak/crdt/base.rb +39 -21
  28. data/lib/riak/crdt/batch_counter.rb +5 -5
  29. data/lib/riak/crdt/batch_map.rb +2 -2
  30. data/lib/riak/crdt/counter.rb +7 -7
  31. data/lib/riak/crdt/inner_counter.rb +4 -4
  32. data/lib/riak/crdt/inner_flag.rb +3 -3
  33. data/lib/riak/crdt/inner_map.rb +1 -1
  34. data/lib/riak/crdt/inner_register.rb +1 -1
  35. data/lib/riak/crdt/inner_set.rb +5 -5
  36. data/lib/riak/crdt/map.rb +9 -9
  37. data/lib/riak/crdt/set.rb +10 -10
  38. data/lib/riak/crdt/typed_collection.rb +39 -36
  39. data/lib/riak/errors/base.rb +1 -1
  40. data/lib/riak/errors/crdt_error.rb +20 -0
  41. data/lib/riak/errors/search_error.rb +6 -0
  42. data/lib/riak/index_collection.rb +1 -1
  43. data/lib/riak/link.rb +5 -3
  44. data/lib/riak/locale/en.yml +5 -1
  45. data/lib/riak/map_reduce.rb +7 -7
  46. data/lib/riak/map_reduce/filter_builder.rb +2 -2
  47. data/lib/riak/map_reduce/phase.rb +2 -2
  48. data/lib/riak/preflist_item.rb +7 -0
  49. data/lib/riak/rcontent.rb +8 -8
  50. data/lib/riak/robject.rb +27 -14
  51. data/lib/riak/search.rb +1 -0
  52. data/lib/riak/search/index.rb +17 -3
  53. data/lib/riak/search/query.rb +14 -6
  54. data/lib/riak/search/result_collection.rb +56 -3
  55. data/lib/riak/search/result_document.rb +71 -1
  56. data/lib/riak/search/schema.rb +6 -6
  57. data/lib/riak/secondary_index.rb +20 -12
  58. data/lib/riak/serializers.rb +0 -1
  59. data/lib/riak/util/escape.rb +2 -2
  60. data/lib/riak/util/translation.rb +1 -2
  61. data/lib/riak/version.rb +1 -1
  62. data/lib/riak/walk_spec.rb +67 -32
  63. data/riak-client.gemspec +5 -4
  64. data/spec/integration/riak/bucket_types_spec.rb +35 -5
  65. data/spec/integration/riak/conflict_resolution_spec.rb +1 -1
  66. data/spec/integration/riak/counters_spec.rb +1 -1
  67. data/spec/integration/riak/crdt/configuration_spec.rb +37 -0
  68. data/spec/integration/riak/crdt_search_spec.rb +176 -0
  69. data/spec/integration/riak/crdt_spec.rb +9 -33
  70. data/spec/integration/riak/crdt_validation/map_spec.rb +4 -4
  71. data/spec/integration/riak/crdt_validation/set_spec.rb +13 -13
  72. data/spec/integration/riak/preflist_spec.rb +31 -0
  73. data/spec/integration/riak/protobuffs/interrupted_request_spec.rb +2 -2
  74. data/spec/integration/riak/protobuffs_backends_spec.rb +9 -2
  75. data/spec/integration/riak/search_spec.rb +3 -3
  76. data/spec/integration/riak/secondary_index_spec.rb +3 -3
  77. data/spec/integration/riak/security_spec.rb +7 -7
  78. data/spec/integration/yokozuna/queries_spec.rb +1 -1
  79. data/spec/riak/beefcake_protobuffs_backend/bucket_properties_operator_spec.rb +9 -9
  80. data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +9 -9
  81. data/spec/riak/beefcake_protobuffs_backend/protocol_spec.rb +5 -5
  82. data/spec/riak/beefcake_protobuffs_backend_spec.rb +8 -8
  83. data/spec/riak/bucket_properties_spec.rb +27 -6
  84. data/spec/riak/bucket_spec.rb +5 -5
  85. data/spec/riak/bucket_type_spec.rb +21 -5
  86. data/spec/riak/bucket_typed/bucket_spec.rb +62 -0
  87. data/spec/riak/client_spec.rb +36 -18
  88. data/spec/riak/counter_spec.rb +4 -4
  89. data/spec/riak/crdt/counter_spec.rb +2 -2
  90. data/spec/riak/crdt/inner_flag_spec.rb +2 -2
  91. data/spec/riak/crdt/inner_map_spec.rb +4 -4
  92. data/spec/riak/crdt/inner_register_spec.rb +1 -1
  93. data/spec/riak/crdt/map_spec.rb +4 -4
  94. data/spec/riak/crdt/shared_examples.rb +5 -5
  95. data/spec/riak/crdt/typed_collection_spec.rb +21 -21
  96. data/spec/riak/map_reduce/filter_builder_spec.rb +2 -2
  97. data/spec/riak/map_reduce/phase_spec.rb +4 -4
  98. data/spec/riak/map_reduce_spec.rb +60 -42
  99. data/spec/riak/multiget_spec.rb +2 -2
  100. data/spec/riak/robject_spec.rb +55 -14
  101. data/spec/riak/search/index_spec.rb +12 -2
  102. data/spec/riak/search/query_spec.rb +4 -4
  103. data/spec/riak/search/result_collection_spec.rb +6 -4
  104. data/spec/riak/search/result_document_spec.rb +52 -9
  105. data/spec/riak/search/schema_spec.rb +2 -2
  106. data/spec/riak/secondary_index_spec.rb +6 -6
  107. data/spec/riak/serializers_spec.rb +27 -10
  108. data/spec/riak/walk_spec_spec.rb +10 -6
  109. data/spec/spec_helper.rb +11 -2
  110. data/spec/support/crdt_search_config.rb +112 -0
  111. data/spec/support/crdt_search_fixtures.rb +42 -0
  112. data/spec/support/search_config.rb +7 -5
  113. data/spec/support/search_corpus_setup.rb +2 -2
  114. data/spec/support/test_client.rb +2 -2
  115. data/spec/support/unified_backend_examples.rb +5 -5
  116. data/spec/support/version_filter.rb +5 -3
  117. data/spec/support/wait_until.rb +9 -3
  118. metadata +36 -13
  119. data/spec/riak/bucket_typed/bucket.rb +0 -43
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 516d08bb526f4cffe8b94314f766a3424e58b884
4
- data.tar.gz: 317c345920e67e8035662a5ecf7ab6aaf5533774
3
+ metadata.gz: 2dd52a7e386245c3d3dc1d7c1be2ba94b3dd2c91
4
+ data.tar.gz: 48ed739d11831361ca42d2c8291753c9d87c7124
5
5
  SHA512:
6
- metadata.gz: 9b251487856bf8dfba41427a8f1370a97541662d47c5047ee5d6a5f7f2b7567630a32b741cd821ce2320adae76ca4e334672f6fef267e7b7117941b1b77c1d0a
7
- data.tar.gz: f4da60a9d5a7254e9541fa87e97fd32acd67da05a5024d972cb23e23ff1e30d93601c132266d29200eb907bdbcc9141495b6b7d490ea5f8f7f3ab3559dbc3ce6
6
+ metadata.gz: dc420b627bd2854197b03468a4aaf09895eb267f601fb285280788ff73754266b098d9fac1251354f662853eb8e4c73973a75874d040e9fa3019a64adac6d86a
7
+ data.tar.gz: f07cc587b55e1b54662b86f3ca572df999f89511ed8ae340ed935848a410d5b9bcb7947f7cc96a569121ddc270e595eedf9e19518f1266fa0cbe7b7d04e5229a
data/.gitignore CHANGED
@@ -39,3 +39,4 @@ vendor/erlang
39
39
  vendor/riak
40
40
  .ruby-version
41
41
  tmp
42
+ tags
data/Gemfile CHANGED
@@ -15,5 +15,3 @@ end
15
15
  platforms :jruby, :rbx do
16
16
  gem 'json'
17
17
  end
18
-
19
- gem 'beefcake', '1.1.0.pre1'
data/README.markdown CHANGED
@@ -5,9 +5,13 @@ distributed database that contains a basic wrapper around typical
5
5
  operations, including bucket manipulation, object CRUD, link-walking,
6
6
  and map-reduce.
7
7
 
8
+ Exhaustive documentation is available at
9
+ http://basho.github.io/riak-ruby-client/ , and API documentation can be
10
+ read at http://www.rubydoc.info/gems/riak-client/frames .
11
+
8
12
  ## Dependencies
9
13
 
10
- Ruby 1.9.3, 2.0, and 2.1 are supported. JRuby in 1.9 and 2.0 modes are
14
+ Ruby 1.9.3, 2.0, 2.1, and 2.2 are supported. JRuby in 1.9 and 2.0 modes are
11
15
  also supported. `riak-client` is not compatible with Ruby 1.8.
12
16
 
13
17
  In JRuby 1.7.13, OCSP validation is absent, and CRL validation always
@@ -19,25 +23,25 @@ when it works.
19
23
  [1]: https://github.com/jruby/jruby-openssl/issues/5
20
24
  [2]: https://github.com/basho/riak_api/issues/65
21
25
 
22
- `riak-client` requires i18n, builder, beefcake, and multi_json. The
23
- cache store implementation requires ActiveSupport 3 or later.
26
+ `riak-client` requires beefcake, cert_validator, i18n, innertube, and
27
+ multi_json.
24
28
 
25
29
  Development dependencies are handled with bundler. Install bundler
26
30
  (`gem install bundler`) and run this command to get started:
27
31
 
28
- ``` bash
32
+ ```bash
29
33
  $ bundle install
30
34
  ```
31
35
 
32
36
  Run the RSpec suite using `bundle exec`:
33
37
 
34
- ``` bash
38
+ ```bash
35
39
  $ bundle exec rake
36
40
  ```
37
41
 
38
42
  ## Basic Example
39
43
 
40
- ``` ruby
44
+ ```ruby
41
45
  require 'riak'
42
46
 
43
47
  # Create a client interface
@@ -622,7 +626,7 @@ search.admin,search.query,riak_kv.mapreduce on any to user
622
626
 
623
627
  ## License & Copyright
624
628
 
625
- Copyright ©2010-2014 Sean Cribbs and Basho Technologies, Inc.
629
+ Copyright ©2010-2015 Sean Cribbs and Basho Technologies, Inc.
626
630
 
627
631
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
628
632
 
data/RELEASE_NOTES.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Riak Ruby Client Release Notes
2
2
 
3
+ ## 2.2.0 Release - 2015-05-27
4
+
5
+ Version 2.2.0 is a feature release.
6
+
7
+ New features:
8
+
9
+ * Object-oriented Riak Search (Yokozuna) API.
10
+ * Object-oriented Bucket Properties API.
11
+ * Bucket type properties are readable.
12
+ * Bucket-typed buckets without properties expose properties of bucket type.
13
+ * An interface to get a preflist for Riak KV objects has been added.
14
+
15
+ Small improvements and changes:
16
+
17
+ * In line with recent Riak documentation and implementation changes, `vclock`
18
+ can also be referred to as `causal_context`.
19
+ * Support for synchronous Riak Search index creation with timeouts has been
20
+ added.
21
+
22
+ Bug fixes:
23
+
24
+ * Accessing a flag in a non-existent CRDT map returns false now.
25
+ * Escaping text in situations that require it is faster, thanks to Jordan
26
+ Goldstein.
27
+ * Loading and storing objects from bucket-typed buckets is more reliable and
28
+ correct thanks to Takeshi Akima.
29
+
3
30
  ## 2.1.0 Release - 2014-10-03
4
31
 
5
32
  Version 2.1.0 is a feature release.
@@ -88,7 +115,7 @@ Features for all Riak versions:
88
115
 
89
116
  * Multi-get parallelizes fetching multiple objects from one or more
90
117
  buckets.
91
-
118
+
92
119
  Features for Riak 1.4 and newer:
93
120
 
94
121
  * Bucket properties are settable and resettable over Protocol Buffers.
@@ -209,7 +236,7 @@ Changes in 1.0.4:
209
236
  * A function in the `app_helper` module that does not exist on Riak
210
237
  1.1 and earlier was copied into the KV test backend.
211
238
  * Excon's configuration logic was made more idempotent.
212
- * Added timeout support to the Excon HTTP backend. [Mat Brown]
239
+ * Added timeout support to the Excon HTTP backend. [Mat Brown]
213
240
  * Corrected an misnamed constant in Excon which would cause timeouts
214
241
  not to be recognized as network errors.
215
242
  * The `Riak::TestServer` is now compatible with Riak 1.2.
data/Rakefile CHANGED
@@ -92,13 +92,13 @@ namespace :beefcake do
92
92
 
93
93
  PROTO_FILES = %w{riak_kv riak_search riak_yokozuna riak_dt}
94
94
  PROTO_TMP = PROTO_FILES.map{|f| "tmp/#{f}.pb.rb"}
95
-
95
+
96
96
  task :clean do
97
97
  sh "rm -rf tmp/riak_pb"
98
98
  sh "rm -rf #{PROTO_TMP.join ' '}"
99
99
  end
100
100
 
101
-
101
+
102
102
  file 'lib/riak/client/beefcake/messages.rb' => PROTO_TMP do |t|
103
103
  sh "cat lib/riak/client/beefcake/header tmp/riak.pb.rb #{t.prerequisites.join ' '} lib/riak/client/beefcake/footer > #{t.name}"
104
104
  end
@@ -109,7 +109,9 @@ namespace :beefcake do
109
109
  end
110
110
  end
111
111
 
112
- directory 'tmp/riak_pb' do
112
+ directory 'tmp'
113
+
114
+ directory 'tmp/riak_pb' => 'tmp' do
113
115
  cd 'tmp' do
114
116
  sh "git clone -b develop https://github.com/basho/riak_pb.git"
115
117
  end
data/lib/riak/bucket.rb CHANGED
@@ -37,7 +37,7 @@ module Riak
37
37
  # @return [Array<String>] Keys in this bucket
38
38
  # @note This operation has serious performance implications and
39
39
  # should not be used in production applications.
40
- def keys(options={}, &block)
40
+ def keys(options = {}, &block)
41
41
  warn(t('list_keys', :backtrace => caller.join("\n "))) unless Riak.disable_list_keys_warnings
42
42
  if block_given?
43
43
  @client.list_keys(self, options, &block)
@@ -51,7 +51,8 @@ module Riak
51
51
  # @param [Hash] properties new properties for the bucket
52
52
  # @option properties [Fixnum] :n_val (3) The N value (replication factor)
53
53
  # @option properties [true,false] :allow_mult (false) Whether to permit object siblings
54
- # @option properties [true,false] :last_write_wins (false) Whether to ignore vclocks
54
+ # @option properties [true,false] :last_write_wins (false) Whether to ignore
55
+ # causal context in regular key-value buckets
55
56
  # @option properties [Array<Hash>] :precommit ([]) precommit hooks
56
57
  # @option properties [Array<Hash>] :postcommit ([])postcommit hooks
57
58
  # @option properties [Fixnum,String] :r ("quorum") read quorum (numeric or
@@ -92,10 +93,12 @@ module Riak
92
93
  # Retrieve an object from within the bucket.
93
94
  # @param [String] key the key of the object to retrieve
94
95
  # @param [Hash] options query parameters for the request
95
- # @option options [Fixnum] :r - the read quorum for the request - how many nodes should concur on the read
96
+ # @option options [Fixnum] :r - the read quorum for the request - how many
97
+ # nodes should concur on the read
96
98
  # @return [Riak::RObject] the object
97
- # @raise [FailedRequest] if the object is not found or some other error occurs
98
- def get(key, options={})
99
+ # @raise [FailedRequest] if the object is not found or some other error
100
+ # occurs
101
+ def get(key, options = {})
99
102
  @client.get_object(self, key, options)
100
103
  end
101
104
  alias :[] :get
@@ -106,22 +109,26 @@ module Riak
106
109
  def get_many(keys)
107
110
  pairs = keys.map{|k| [self, k]}
108
111
  results = Multiget.get_all @client, pairs
109
- results.keys.inject(Hash.new) { |mem, var| mem[var[1]] = results[var]; mem }
112
+ results.keys.inject(Hash.new) do |mem, var|
113
+ mem[var[1]] = results[var]
114
+ mem
115
+ end
110
116
  end
111
117
 
112
118
  # Create a new blank object
113
119
  # @param [String] key the key of the new object
114
120
  # @return [RObject] the new, unsaved object
115
- def new(key=nil)
121
+ def new(key = nil)
116
122
  RObject.new(self, key).tap do |obj|
117
123
  obj.content_type = "application/json"
118
124
  end
119
125
  end
120
126
 
121
- # Fetches an object if it exists, otherwise creates a new one with the given key
127
+ # Fetches an object if it exists, otherwise creates a new one with the
128
+ # given key
122
129
  # @param [String] key the key to fetch or create
123
130
  # @return [RObject] the new or existing object
124
- def get_or_new(key, options={})
131
+ def get_or_new(key, options = {})
125
132
  begin
126
133
  get(key, options)
127
134
  rescue Riak::FailedRequest => fr
@@ -146,7 +153,7 @@ module Riak
146
153
  # @param [Hash] options quorum options
147
154
  # @option options [Fixnum] :r - the read quorum value for the request (R)
148
155
  # @return [true, false] whether the key exists in this bucket
149
- def exists?(key, options={})
156
+ def exists?(key, options = {})
150
157
  begin
151
158
  get(key, options.merge({ :head => true }))
152
159
  true
@@ -162,9 +169,9 @@ module Riak
162
169
  # @param [Hash] options quorum options
163
170
  # @option options [Fixnum] :rw - the read/write quorum for the
164
171
  # delete
165
- # @option options [String] :vclock - the vector clock of the
172
+ # @option options [String] :vclock - the causal context/vector clock of the
166
173
  # object being deleted
167
- def delete(key, options={})
174
+ def delete(key, options = {})
168
175
  client.delete_object(self, key, options)
169
176
  end
170
177
 
@@ -175,16 +182,27 @@ module Riak
175
182
  # Range of values to query
176
183
  # @return [Array<String>] a list of keys that match the index
177
184
  # query
178
- def get_index(index, query, options={})
185
+ def get_index(index, query, options = {})
179
186
  client.get_index(self, index, query, options)
180
187
  end
181
188
 
189
+
190
+ # Retrieves a preflist for the given key; useful for
191
+ # figuring out where in the cluster an object is stored.
192
+ # @param [String] key the key
193
+ # @return [Array<PreflistItem>] an array of preflist entries
194
+ def get_preflist(key, options = { })
195
+ type = self.type.name if needs_type?
196
+ client.get_preflist self, key, type, options
197
+ end
198
+
182
199
  # @return [true, false] whether the bucket allows divergent siblings
183
200
  def allow_mult
184
201
  props['allow_mult']
185
202
  end
186
203
 
187
- # Set the allow_mult property. *NOTE* This will result in a PUT request to Riak.
204
+ # Set the allow_mult property. *NOTE* This will result in a PUT request to
205
+ # Riak.
188
206
  # @param [true, false] value whether the bucket should allow siblings
189
207
  def allow_mult=(value)
190
208
  self.props = {'allow_mult' => value}
@@ -197,9 +215,11 @@ module Riak
197
215
  end
198
216
  alias :n_val :n_value
199
217
 
200
- # Set the N value (number of replicas). *NOTE* This will result in a PUT request to Riak.
201
- # Setting this value after the bucket has objects stored in it may have unpredictable results.
202
- # @param [Fixnum] value the number of replicas the bucket should keep of each object
218
+ # Set the N value (number of replicas). *NOTE* This will result in a PUT
219
+ # request to Riak. Setting this value after the bucket has objects stored in
220
+ # it may have unpredictable results.
221
+ # @param [Fixnum] value the number of replicas the bucket should keep of
222
+ # each object
203
223
  def n_value=(value)
204
224
  self.props = {'n_val' => value}
205
225
  value
@@ -218,15 +238,21 @@ module Riak
218
238
  # into riak_search.
219
239
  def enable_index!
220
240
  unless is_indexed?
221
- self.props = {"precommit" => (props['precommit'] + [SEARCH_PRECOMMIT_HOOK]), "search" => true}
241
+ self.props = {
242
+ "precommit" => (props['precommit'] + [SEARCH_PRECOMMIT_HOOK]),
243
+ "search" => true
244
+ }
222
245
  end
223
246
  end
224
247
 
225
- # (Riak Search) Removes the precommit hook that automatically indexes objects
226
- # into riak_search.
248
+ # (Riak Search) Removes the precommit hook that automatically indexes
249
+ # objects into riak_search.
227
250
  def disable_index!
228
251
  if is_indexed?
229
- self.props = {"precommit" => (props['precommit'] - [SEARCH_PRECOMMIT_HOOK]), "search" => false}
252
+ self.props = {
253
+ "precommit" => (props['precommit'] - [SEARCH_PRECOMMIT_HOOK]),
254
+ "search" => false
255
+ }
230
256
  end
231
257
  end
232
258
 
@@ -234,7 +260,10 @@ module Riak
234
260
  # riak_search.
235
261
  # @return [true,false] whether the bucket includes the search indexing hook
236
262
  def is_indexed?
237
- props['search'] == true || (props.has_key?('precommit') && props['precommit'].include?(SEARCH_PRECOMMIT_HOOK))
263
+ return true if props['search'] == true
264
+ return true if props.has_key?('precommit') &&
265
+ props['precommit'].include?(SEARCH_PRECOMMIT_HOOK)
266
+ false
238
267
  end
239
268
 
240
269
  # @return [String] a representation suitable for IRB and debugging output
@@ -259,7 +288,10 @@ module Riak
259
288
 
260
289
  # @return [true,false] whether the other is equivalent
261
290
  def ==(other)
262
- Bucket === other && other.client == client && other.name == name
291
+ return false unless self.class == other.class
292
+ return false unless self.client == other.client
293
+ return false unless self.name == other.name
294
+ true
263
295
  end
264
296
  end
265
297
  end
@@ -30,7 +30,7 @@ module Riak
30
30
  return true
31
31
  end
32
32
 
33
- # Take bucket properties from a given {Hash} or {Riak::BucketProperties}
33
+ # Take bucket properties from a given {Hash} or {Riak::BucketProperties}
34
34
  # object.
35
35
  # @param [Hash<String, Object>, Riak::BucketProperties] other
36
36
  def merge!(other)
@@ -54,6 +54,7 @@ module Riak
54
54
  # @param [String] property_name
55
55
  # @param [Object] value
56
56
  def []=(property_name, value)
57
+ value = unwrap_index(value) if property_name == 'search_index'
57
58
  cached_props[property_name.to_s] = value
58
59
  end
59
60
 
@@ -63,5 +64,11 @@ module Riak
63
64
  be.bucket_properties_operator.get bucket
64
65
  end
65
66
  end
67
+
68
+ def unwrap_index(value)
69
+ return value.name if value.is_a? Riak::Search::Index
70
+
71
+ value
72
+ end
66
73
  end
67
74
  end
@@ -1,4 +1,5 @@
1
1
  require 'riak/bucket_typed/bucket'
2
+ require 'riak/errors/crdt_error'
2
3
 
3
4
  module Riak
4
5
  # A representation of a bucket type
@@ -44,5 +45,33 @@ module Riak
44
45
  end
45
46
  alias :props :properties
46
47
 
48
+ # Return the data type used for handling the CRDT stored in this bucket
49
+ # type.
50
+ # Returns `nil` for a non-CRDT bucket type.
51
+ # @raise [Riak::CrdtError::UnrecognizedDataType] if the bucket type has an
52
+ # unknown datatype
53
+ # @return [Class<Riak::Crdt::Base>] CRDT subclass to use with this bucket
54
+ # type
55
+ def data_type_class
56
+ return nil unless dt = properties[:datatype]
57
+ parent = Riak::Crdt
58
+ case dt
59
+ when 'counter'
60
+ parent::Counter
61
+ when 'map'
62
+ parent::Map
63
+ when 'set'
64
+ parent::Set
65
+ else
66
+ raise CrdtError::UnrecognizedDataType.new dt
67
+ end
68
+ end
69
+
70
+ def ==(other)
71
+ return false unless self.class == other.class
72
+ return false unless self.client == other.client
73
+ return false unless self.name == other.name
74
+ true
75
+ end
47
76
  end
48
77
  end
@@ -2,16 +2,16 @@ require 'riak/bucket'
2
2
  require 'riak/bucket_type'
3
3
 
4
4
  module Riak
5
-
5
+
6
6
  # Container module for subclasses of objects with bucket type data attached.
7
7
  # Currently only used for {BucketTyped::Bucket}.
8
8
  module BucketTyped
9
-
9
+
10
10
  # A bucket that has a {BucketType} attached to it. Normally created using
11
11
  # the {BucketType#bucket} method. Inherits most of its behavior from the
12
12
  # {Riak::Bucket} class.
13
13
  class Bucket < Riak::Bucket
14
-
14
+
15
15
  # @return [BucketType] the bucket type used with this bucket
16
16
  attr_reader :type
17
17
 
@@ -37,8 +37,10 @@ module Riak
37
37
  # @option options [Fixnum] :r - the read quorum for the request - how many nodes should concur on the read
38
38
  # @return [Riak::RObject] the object
39
39
  # @raise [FailedRequest] if the object is not found or some other error occurs
40
- def get(key, options={ })
41
- super key, o(options)
40
+ def get(key, options = { })
41
+ object = super key, o(options)
42
+ object.bucket = self
43
+ return object
42
44
  end
43
45
  alias :[] :get
44
46
 
@@ -49,7 +51,7 @@ module Riak
49
51
  # delete
50
52
  # @option options [String] :vclock - the vector clock of the
51
53
  # object being deleted
52
- def delete(key, options={ })
54
+ def delete(key, options = { })
53
55
  super key, o(options)
54
56
  end
55
57
 
@@ -61,7 +63,7 @@ module Riak
61
63
  # @return [Array<String>] Keys in this bucket
62
64
  # @note This operation has serious performance implications and
63
65
  # should not be used in production applications.
64
- def keys(options={ }, &block)
66
+ def keys(options = { }, &block)
65
67
  super o(options), &block
66
68
  end
67
69
 
@@ -103,6 +105,12 @@ module Riak
103
105
  return false
104
106
  end
105
107
 
108
+ def ==(other)
109
+ return false unless self.class == other.class
110
+ return false unless self.type == other.type
111
+ super
112
+ end
113
+
106
114
  private
107
115
  # merge in the type name with options
108
116
  def o(options)