couchbase 1.1.0-x86-mingw32 → 1.1.1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.markdown CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.1.1 / 2012-03-19
2
+
3
+ * Allow to force format for get operation (thanks to Darian Shimy)
4
+ * Use all arguments if receiver arity is -1 (couchbase_ext.c)
5
+ * Doc fixes
6
+
1
7
  ## 1.1.0 / 2012-03-07
2
8
 
3
9
  * Timeout support (CCBC-20)
data/README.markdown CHANGED
@@ -81,26 +81,34 @@ as the endpoint. The client will automatically adjust configuration when
81
81
  the cluster will rebalance its nodes when nodes are added or deleted
82
82
  therefore this client is "smart".
83
83
 
84
- c = Couchbase.new
84
+ c = Couchbase.connect
85
85
 
86
86
  This is equivalent to following forms:
87
87
 
88
- c = Couchbase.new("http://localhost:8091/pools/default/buckets/default")
89
- c = Couchbase.new("http://localhost:8091/pools/default")
90
- c = Couchbase.new("http://localhost:8091")
91
- c = Couchbase.new(:host => "localhost")
92
- c = Couchbase.new(:host => "localhost", :port => 8091)
93
- c = Couchbase.new(:pool => "default", :bucket => "default")
88
+ c = Couchbase.connect("http://localhost:8091/pools/default/buckets/default")
89
+ c = Couchbase.connect("http://localhost:8091/pools/default")
90
+ c = Couchbase.connect("http://localhost:8091")
91
+ c = Couchbase.connect(:hostname => "localhost")
92
+ c = Couchbase.connect(:hostname => "localhost", :port => 8091)
93
+ c = Couchbase.connect(:pool => "default", :bucket => "default")
94
94
 
95
95
  The hash parameters take precedence on string URL.
96
96
 
97
+ There is also handy method `Couchbase.bucket` which uses thread local
98
+ storage to keep the reference to default connection. You can set the
99
+ connection options via `Couchbase.connection_options`:
100
+
101
+ Couchbase.connection_options = {:bucket => 'blog'}
102
+ Couchbase.bucket.name #=> "blog"
103
+ Couchbase.bucket.set("foo", "bar") #=> 3289400178357895424
104
+
97
105
  The library supports both synchronous and asynchronous mode. In
98
106
  asynchronous mode all operations will return control to caller
99
107
  without blocking current thread. You can pass the block to method and it
100
108
  will be called with result when the operation will be completed. You
101
109
  need to run event loop when you scheduled your operations:
102
110
 
103
- c = Couchbase.new
111
+ c = Couchbase.connect
104
112
  c.run do |conn|
105
113
  conn.get("foo") {|ret| puts ret.value}
106
114
  conn.set("bar", "baz")
@@ -166,12 +174,12 @@ The library supports three different formats for representing values:
166
174
  version will be able to run map/reduce queries on the values in the
167
175
  document form (hashes)
168
176
 
169
- * `:marshal` This format avoids any conversions to be applied to your
177
+ * `:plain` This format avoids any conversions to be applied to your
170
178
  data, but your data should be passed as String. This is useful for
171
179
  building custom algorithms or formats. For example to implement a set:
172
180
  http://dustin.github.com/2011/02/17/memcached-set.html
173
181
 
174
- * `:plain` Use this format if you'd like to transparently serialize your
182
+ * `:marshal` Use this format if you'd like to transparently serialize your
175
183
  ruby object with standard `Marshal.dump` and `Marshal.load` methods
176
184
 
177
185
  The couchbase API is the superset of [Memcached binary protocol][5], so
@@ -73,6 +73,7 @@ typedef struct
73
73
  VALUE proc;
74
74
  void *rv;
75
75
  VALUE exception;
76
+ VALUE force_format;
76
77
  int quiet;
77
78
  int arithm; /* incr: +1, decr: -1, other: 0 */
78
79
  } context_t;
@@ -88,6 +89,7 @@ struct key_traits
88
89
  int explicit_ttl;
89
90
  int quiet;
90
91
  int mgat;
92
+ VALUE force_format;
91
93
  };
92
94
 
93
95
  static VALUE mCouchbase, mError, mJSON, mURI, mMarshal, cBucket, cResult;
@@ -190,6 +192,9 @@ cb_proc_call(VALUE recv, int argc, ...)
190
192
  int ii;
191
193
 
192
194
  arity = FIX2INT(rb_funcall(recv, id_arity, 0));
195
+ if (arity < 0) {
196
+ arity = argc;
197
+ }
193
198
  if (arity > 0) {
194
199
  va_init_list(ar, argc);
195
200
  argv = ALLOCA_N(VALUE, argc);
@@ -202,7 +207,6 @@ cb_proc_call(VALUE recv, int argc, ...)
202
207
  }
203
208
  va_end(ar);
204
209
  } else {
205
- arity = 0;
206
210
  argv = NULL;
207
211
  }
208
212
  return rb_funcall2(recv, id_call, arity, argv);
@@ -367,18 +371,30 @@ do_encode(VALUE *args)
367
371
  do_decode(VALUE *args)
368
372
  {
369
373
  VALUE blob = args[0];
370
- uint32_t flags = ((uint32_t)args[1] & FMT_MASK);
374
+ VALUE force_format = args[2];
371
375
 
372
- switch (flags) {
373
- case FMT_DOCUMENT:
376
+ if (TYPE(force_format) == T_SYMBOL) {
377
+ if (force_format == sym_document) {
374
378
  return rb_funcall(mJSON, id_load, 1, blob);
375
- case FMT_MARSHAL:
379
+ } else if (force_format == sym_marshal) {
376
380
  return rb_funcall(mMarshal, id_load, 1, blob);
377
- case FMT_PLAIN:
378
- /* fall through */
379
- default:
380
- /* all other formats treated as plain */
381
+ } else { /* sym_plain and any other symbol */
381
382
  return blob;
383
+ }
384
+ } else {
385
+ uint32_t flags = ((uint32_t)args[1] & FMT_MASK);
386
+
387
+ switch (flags) {
388
+ case FMT_DOCUMENT:
389
+ return rb_funcall(mJSON, id_load, 1, blob);
390
+ case FMT_MARSHAL:
391
+ return rb_funcall(mMarshal, id_load, 1, blob);
392
+ case FMT_PLAIN:
393
+ /* fall through */
394
+ default:
395
+ /* all other formats treated as plain */
396
+ return blob;
397
+ }
382
398
  }
383
399
  }
384
400
 
@@ -404,9 +420,9 @@ encode_value(VALUE val, uint32_t flags)
404
420
  }
405
421
 
406
422
  static VALUE
407
- decode_value(VALUE blob, uint32_t flags)
423
+ decode_value(VALUE blob, uint32_t flags, VALUE force_format)
408
424
  {
409
- VALUE val, args[2];
425
+ VALUE val, args[3];
410
426
 
411
427
  /* first it must be bytestring */
412
428
  if (TYPE(blob) != T_STRING) {
@@ -414,6 +430,7 @@ decode_value(VALUE blob, uint32_t flags)
414
430
  }
415
431
  args[0] = blob;
416
432
  args[1] = (VALUE)flags;
433
+ args[2] = (VALUE)force_format;
417
434
  val = rb_rescue(do_decode, (VALUE)args, coding_failed, 0);
418
435
  return val;
419
436
  }
@@ -465,6 +482,10 @@ cb_args_scan_keys(long argc, VALUE argv, bucket_t *bucket, struct key_traits *tr
465
482
  if (RTEST(rb_funcall(opts, id_has_key_p, 1, sym_quiet))) {
466
483
  traits->quiet = RTEST(rb_hash_aref(opts, sym_quiet));
467
484
  }
485
+ traits->force_format = rb_hash_aref(opts, sym_format);
486
+ if (traits->force_format != Qnil) {
487
+ Check_Type(traits->force_format, T_SYMBOL);
488
+ }
468
489
  ext = rb_hash_aref(opts, sym_extended);
469
490
  ttl = rb_hash_aref(opts, sym_ttl);
470
491
  if (ttl != Qnil) {
@@ -644,9 +665,11 @@ get_callback(libcouchbase_t handle, const void *cookie,
644
665
  f = ULONG2NUM(flags);
645
666
  c = ULL2NUM(cas);
646
667
  if (nbytes != 0) {
647
- v = decode_value(rb_str_new((const char*)bytes, nbytes), flags);
668
+ v = decode_value(rb_str_new((const char*)bytes, nbytes), flags, ctx->force_format);
648
669
  if (v == Qundef) {
649
670
  ctx->exception = rb_exc_new2(eValueFormatError, "unable to convert value");
671
+ rb_ivar_set(ctx->exception, id_iv_operation, sym_get);
672
+ rb_ivar_set(ctx->exception, id_iv_key, k);
650
673
  v = Qnil;
651
674
  }
652
675
  } else {
@@ -2082,6 +2105,9 @@ cb_bucket_decr(int argc, VALUE *argv, VALUE self)
2082
2105
  * operation won't raise error for missing key, it will return +nil+.
2083
2106
  * Otherwise it will raise error in synchronous mode. In asynchronous
2084
2107
  * mode this option ignored.
2108
+ * @option options [Symbol] :format (nil) Explicitly choose the decoder
2109
+ * for this key (+:plain+, +:document+, +:marshal+). See
2110
+ * {Bucket#default_format}.
2085
2111
  *
2086
2112
  * @yieldparam ret [Result] the result of operation in asynchronous mode
2087
2113
  * (valid attributes: +error+, +operation+, +key+, +value+, +flags+,
@@ -2184,6 +2210,7 @@ cb_bucket_get(int argc, VALUE *argv, VALUE self)
2184
2210
  ctx->bucket = bucket;
2185
2211
  ctx->extended = traits->extended;
2186
2212
  ctx->quiet = traits->quiet;
2213
+ ctx->force_format = traits->force_format;
2187
2214
  rv = rb_hash_new();
2188
2215
  ctx->rv = &rv;
2189
2216
  ctx->exception = Qnil;
@@ -17,5 +17,5 @@
17
17
 
18
18
  # Couchbase ruby client
19
19
  module Couchbase
20
- VERSION = "1.1.0"
20
+ VERSION = "1.1.1"
21
21
  end
data/test/test_get.rb CHANGED
@@ -308,4 +308,23 @@ class TestGet < MiniTest::Unit::TestCase
308
308
  assert_equal nil, connection.get(uniq_id, :quiet => false)
309
309
  end
310
310
 
311
+ def test_format_forcing
312
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
313
+
314
+ connection.set(uniq_id, '{"foo":"bar"}', :format => :plain)
315
+ value, flags, _ = connection.get(uniq_id, :extended => true)
316
+ assert_equal '{"foo":"bar"}', value
317
+ assert_equal 0x02, flags
318
+
319
+ value, flags, _ = connection.get(uniq_id, :extended => true, :format => :document)
320
+ expected = {"foo" => "bar"}
321
+ assert_equal expected, value
322
+ assert_equal 0x02, flags
323
+
324
+ connection.prepend(uniq_id, "NOT-A-JSON")
325
+ assert_raises Couchbase::Error::ValueFormat do
326
+ connection.get(uniq_id, :format => :document)
327
+ end
328
+ end
329
+
311
330
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couchbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: x86-mingw32
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-07 00:00:00.000000000Z
12
+ date: 2012-03-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yajl-ruby
16
- requirement: &12069760 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 1.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *12069760
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rake
27
- requirement: &12068240 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 0.8.7
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *12068240
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.8.7
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: minitest
38
- requirement: &12067280 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *12067280
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rake-compiler
49
- requirement: &12056580 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: 0.7.5
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *12056580
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.7.5
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: rdiscount
60
- requirement: &12055480 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *12055480
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: yard
71
- requirement: &12054260 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
@@ -76,10 +101,15 @@ dependencies:
76
101
  version: '0'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *12054260
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: mini_portile
82
- requirement: &12053280 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ! '>='
@@ -87,10 +117,15 @@ dependencies:
87
117
  version: '0'
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *12053280
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
91
126
  - !ruby/object:Gem::Dependency
92
127
  name: ruby-debug19
93
- requirement: &12052340 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
94
129
  none: false
95
130
  requirements:
96
131
  - - ! '>='
@@ -98,7 +133,12 @@ dependencies:
98
133
  version: '0'
99
134
  type: :development
100
135
  prerelease: false
101
- version_requirements: *12052340
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
102
142
  description: The official client library for use with Couchbase Server.
103
143
  email: support@couchbase.com
104
144
  executables: []
@@ -160,7 +200,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
200
  version: '0'
161
201
  segments:
162
202
  - 0
163
- hash: -2404392778258139925
203
+ hash: 64321140772701323
164
204
  required_rubygems_version: !ruby/object:Gem::Requirement
165
205
  none: false
166
206
  requirements:
@@ -169,29 +209,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
209
  version: '0'
170
210
  segments:
171
211
  - 0
172
- hash: -2404392778258139925
212
+ hash: 64321140772701323
173
213
  requirements: []
174
214
  rubyforge_project:
175
- rubygems_version: 1.8.10
215
+ rubygems_version: 1.8.18
176
216
  signing_key:
177
217
  specification_version: 3
178
218
  summary: Couchbase ruby driver
179
- test_files:
180
- - test/profile/.gitignore
181
- - test/profile/Gemfile
182
- - test/profile/benchmark.rb
183
- - test/setup.rb
184
- - test/test_arithmetic.rb
185
- - test/test_async.rb
186
- - test/test_bucket.rb
187
- - test/test_cas.rb
188
- - test/test_couchbase.rb
189
- - test/test_delete.rb
190
- - test/test_errors.rb
191
- - test/test_flush.rb
192
- - test/test_format.rb
193
- - test/test_get.rb
194
- - test/test_stats.rb
195
- - test/test_store.rb
196
- - test/test_touch.rb
197
- - test/test_version.rb
219
+ test_files: []