couchbase 1.2.3 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +1 -1
- data/README.markdown +12 -8
- data/RELEASE_NOTES.markdown +19 -0
- data/couchbase.gemspec +1 -0
- data/examples/chat-goliath-grape/Gemfile +5 -0
- data/examples/chat-goliath-grape/README.markdown +50 -0
- data/examples/chat-goliath-grape/app.rb +67 -0
- data/examples/chat-goliath-grape/config/app.rb +20 -0
- data/examples/transcoders/Gemfile +3 -0
- data/examples/transcoders/README.markdown +59 -0
- data/examples/transcoders/cb-zcat +40 -0
- data/examples/transcoders/cb-zcp +45 -0
- data/examples/transcoders/gzip_transcoder.rb +49 -0
- data/examples/transcoders/options.rb +54 -0
- data/ext/couchbase_ext/arguments.c +67 -22
- data/ext/couchbase_ext/bucket.c +64 -20
- data/ext/couchbase_ext/context.c +2 -1
- data/ext/couchbase_ext/couchbase_ext.c +59 -9
- data/ext/couchbase_ext/couchbase_ext.h +18 -9
- data/ext/couchbase_ext/get.c +19 -23
- data/ext/couchbase_ext/store.c +1 -1
- data/ext/couchbase_ext/utils.c +38 -81
- data/lib/active_support/cache/couchbase_store.rb +60 -23
- data/lib/couchbase.rb +4 -2
- data/lib/couchbase/connection_pool.rb +55 -0
- data/lib/couchbase/transcoder.rb +120 -0
- data/lib/couchbase/version.rb +1 -1
- data/tasks/compile.rake +1 -1
- data/test/test_bucket.rb +1 -1
- data/test/test_couchbase_connection_pool.rb +73 -0
- data/test/test_couchbase_rails_cache_store.rb +36 -12
- data/test/test_format.rb +51 -1
- metadata +184 -127
- checksums.yaml +0 -15
@@ -17,8 +17,6 @@
|
|
17
17
|
|
18
18
|
#include "couchbase_ext.h"
|
19
19
|
|
20
|
-
/* TOUCH */
|
21
|
-
|
22
20
|
#define _alloc_data_for_s(type, _type, size, items, ptr) do {\
|
23
21
|
lcb_size_t ii; \
|
24
22
|
\
|
@@ -45,6 +43,40 @@
|
|
45
43
|
|
46
44
|
#define _release_data_for(type) _release_data_for_s(type, items, ptr)
|
47
45
|
|
46
|
+
static VALUE
|
47
|
+
get_transcoder(struct cb_bucket_st *bucket, VALUE override, int compat, VALUE opts)
|
48
|
+
{
|
49
|
+
VALUE ret = Qundef;
|
50
|
+
|
51
|
+
/* override with symbol */
|
52
|
+
if (TYPE(override) == T_SYMBOL) {
|
53
|
+
if (override == cb_sym_document) {
|
54
|
+
ret = cb_mDocument;
|
55
|
+
} else if (override == cb_sym_marshal) {
|
56
|
+
ret = cb_mMarshal;
|
57
|
+
} else if (override == cb_sym_plain) {
|
58
|
+
ret = cb_mPlain;
|
59
|
+
}
|
60
|
+
} else if (!compat) {
|
61
|
+
/* override with transcoder */
|
62
|
+
if (rb_respond_to(override, cb_id_dump)
|
63
|
+
&& rb_respond_to(override, cb_id_load)) {
|
64
|
+
ret = override;
|
65
|
+
}
|
66
|
+
/* nil is also valid */
|
67
|
+
if (NIL_P(override)) {
|
68
|
+
ret = Qnil;
|
69
|
+
}
|
70
|
+
}
|
71
|
+
if (ret == Qundef) {
|
72
|
+
return bucket->transcoder;
|
73
|
+
} else {
|
74
|
+
rb_hash_aset(opts, cb_sym_forced, Qtrue);
|
75
|
+
return ret;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
/* TOUCH */
|
48
80
|
|
49
81
|
static void
|
50
82
|
cb_params_touch_alloc(struct cb_params_st *params, lcb_size_t size)
|
@@ -227,11 +259,11 @@ cb_params_store_init_item(struct cb_params_st *params, lcb_size_t idx,
|
|
227
259
|
lcb_time_t exptime)
|
228
260
|
{
|
229
261
|
key_obj = cb_unify_key(params->bucket, key_obj, 1);
|
230
|
-
value_obj = cb_encode_value(value_obj, params->cmd.store.
|
262
|
+
value_obj = cb_encode_value(params->cmd.store.transcoder, value_obj, &flags, params->cmd.store.transcoder_opts);
|
231
263
|
if (rb_obj_is_kind_of(value_obj, rb_eStandardError)) {
|
232
264
|
VALUE exc_str = rb_funcall(value_obj, cb_id_to_s, 0);
|
233
265
|
VALUE msg = rb_funcall(rb_mKernel, cb_id_sprintf, 3,
|
234
|
-
rb_str_new2("unable to convert value for key
|
266
|
+
rb_str_new2("unable to convert value for key \"%s\": %s"), key_obj, exc_str);
|
235
267
|
VALUE exc = rb_exc_new3(cb_eValueFormatError, msg);
|
236
268
|
rb_ivar_set(exc, cb_id_iv_inner_exception, value_obj);
|
237
269
|
rb_exc_raise(exc);
|
@@ -239,7 +271,7 @@ cb_params_store_init_item(struct cb_params_st *params, lcb_size_t idx,
|
|
239
271
|
/* the value must be string after conversion */
|
240
272
|
if (TYPE(value_obj) != T_STRING) {
|
241
273
|
VALUE val = rb_any_to_s(value_obj);
|
242
|
-
rb_raise(cb_eValueFormatError, "unable to convert value for key
|
274
|
+
rb_raise(cb_eValueFormatError, "unable to convert value for key \"%s\" to string: %s", RSTRING_PTR(key_obj), RSTRING_PTR(val));
|
243
275
|
}
|
244
276
|
rb_ary_push(params->ensurance, key_obj);
|
245
277
|
rb_ary_push(params->ensurance, value_obj);
|
@@ -276,10 +308,6 @@ cb_params_store_parse_options(struct cb_params_st *params, VALUE options)
|
|
276
308
|
if (tmp != Qnil) {
|
277
309
|
params->cmd.store.flags = (lcb_uint32_t)NUM2ULONG(tmp);
|
278
310
|
}
|
279
|
-
tmp = rb_hash_aref(options, cb_sym_format);
|
280
|
-
if (tmp != Qnil) { /* rewrite format bits */
|
281
|
-
params->cmd.store.flags = cb_flags_set_format(params->cmd.store.flags, tmp);
|
282
|
-
}
|
283
311
|
tmp = rb_hash_aref(options, cb_sym_ttl);
|
284
312
|
if (tmp != Qnil) {
|
285
313
|
params->cmd.store.ttl = NUM2ULONG(tmp);
|
@@ -294,9 +322,15 @@ cb_params_store_parse_options(struct cb_params_st *params, VALUE options)
|
|
294
322
|
rb_funcall(params->bucket->self, cb_id_verify_observe_options, 1, tmp);
|
295
323
|
params->cmd.store.observe = tmp;
|
296
324
|
}
|
297
|
-
|
298
|
-
|
299
|
-
params->cmd.store.
|
325
|
+
tmp = rb_hash_aref(options, cb_sym_format);
|
326
|
+
if (tmp != Qnil) {
|
327
|
+
params->cmd.store.transcoder = get_transcoder(params->bucket,
|
328
|
+
tmp, 1, params->cmd.store.transcoder_opts);
|
329
|
+
}
|
330
|
+
tmp = rb_hash_lookup2(options, cb_sym_transcoder, Qundef);
|
331
|
+
if (tmp != Qundef) {
|
332
|
+
params->cmd.store.transcoder = get_transcoder(params->bucket,
|
333
|
+
tmp, 0, params->cmd.store.transcoder_opts);
|
300
334
|
}
|
301
335
|
}
|
302
336
|
|
@@ -391,8 +425,13 @@ cb_params_get_parse_options(struct cb_params_st *params, VALUE options)
|
|
391
425
|
}
|
392
426
|
tmp = rb_hash_aref(options, cb_sym_format);
|
393
427
|
if (tmp != Qnil) {
|
394
|
-
|
395
|
-
|
428
|
+
params->cmd.get.transcoder = get_transcoder(params->bucket,
|
429
|
+
tmp, 1, params->cmd.get.transcoder_opts);
|
430
|
+
}
|
431
|
+
tmp = rb_hash_lookup2(options, cb_sym_transcoder, Qundef);
|
432
|
+
if (tmp != Qundef) {
|
433
|
+
params->cmd.get.transcoder = get_transcoder(params->bucket,
|
434
|
+
tmp, 0, params->cmd.get.transcoder_opts);
|
396
435
|
}
|
397
436
|
tmp = rb_hash_aref(options, cb_sym_ttl);
|
398
437
|
if (tmp != Qnil) {
|
@@ -511,12 +550,14 @@ cb_params_arith_parse_options(struct cb_params_st *params, VALUE options)
|
|
511
550
|
params->cmd.arith.delta = NUM2ULL(tmp) & INT64_MAX;
|
512
551
|
}
|
513
552
|
tmp = rb_hash_aref(options, cb_sym_format);
|
514
|
-
if (tmp != Qnil) {
|
515
|
-
params->cmd.arith.
|
553
|
+
if (tmp != Qnil) {
|
554
|
+
params->cmd.arith.transcoder = get_transcoder(params->bucket,
|
555
|
+
tmp, 1, params->cmd.arith.transcoder_opts);
|
516
556
|
}
|
517
|
-
|
518
|
-
|
519
|
-
params->cmd.arith.
|
557
|
+
tmp = rb_hash_lookup2(options, cb_sym_transcoder, Qundef);
|
558
|
+
if (tmp != Qundef) {
|
559
|
+
params->cmd.arith.transcoder = get_transcoder(params->bucket,
|
560
|
+
tmp, 0, params->cmd.arith.transcoder_opts);
|
520
561
|
}
|
521
562
|
}
|
522
563
|
|
@@ -824,22 +865,26 @@ do_params_build(VALUE ptr)
|
|
824
865
|
}
|
825
866
|
params->cmd.store.datatype = 0x00;
|
826
867
|
params->cmd.store.ttl = params->bucket->default_ttl;
|
827
|
-
params->cmd.store.flags =
|
828
|
-
params->bucket->default_format);
|
868
|
+
params->cmd.store.flags = params->bucket->default_flags;
|
829
869
|
params->cmd.store.observe = Qnil;
|
870
|
+
params->cmd.store.transcoder = params->bucket->transcoder;
|
871
|
+
params->cmd.store.transcoder_opts = rb_hash_new();
|
830
872
|
cb_params_store_parse_options(params, opts);
|
831
873
|
cb_params_store_parse_arguments(params, argc, argv);
|
832
874
|
break;
|
833
875
|
case cb_cmd_get:
|
834
876
|
params->cmd.get.quiet = params->bucket->quiet;
|
877
|
+
params->cmd.get.transcoder = params->bucket->transcoder;
|
878
|
+
params->cmd.get.transcoder_opts = rb_hash_new();
|
835
879
|
cb_params_get_parse_options(params, opts);
|
836
880
|
cb_params_get_parse_arguments(params, argc, argv);
|
837
881
|
break;
|
838
882
|
case cb_cmd_arith:
|
883
|
+
params->cmd.arith.transcoder = params->bucket->transcoder;
|
884
|
+
params->cmd.arith.transcoder_opts = rb_hash_new();
|
839
885
|
params->cmd.arith.create = params->bucket->default_arith_create;
|
840
886
|
params->cmd.arith.initial = params->bucket->default_arith_init;
|
841
887
|
params->cmd.arith.delta = 1;
|
842
|
-
params->cmd.arith.format = params->bucket->default_format;
|
843
888
|
params->cmd.arith.ttl = params->bucket->default_ttl;
|
844
889
|
if (argc == 2 && TYPE(RARRAY_PTR(argv)[1]) == T_FIXNUM) {
|
845
890
|
/* allow form incr("foo", 1) */
|
data/ext/couchbase_ext/bucket.c
CHANGED
@@ -215,6 +215,7 @@ do_scan_connection_options(struct cb_bucket_st *bucket, int argc, VALUE *argv)
|
|
215
215
|
arg = rb_hash_aref(opts, cb_sym_default_format);
|
216
216
|
if (arg != Qnil) {
|
217
217
|
if (TYPE(arg) == T_FIXNUM) {
|
218
|
+
rb_warn("numeric argument to :default_format option is deprecated, use symbol");
|
218
219
|
switch (FIX2INT(arg)) {
|
219
220
|
case CB_FMT_DOCUMENT:
|
220
221
|
arg = cb_sym_document;
|
@@ -227,12 +228,18 @@ do_scan_connection_options(struct cb_bucket_st *bucket, int argc, VALUE *argv)
|
|
227
228
|
break;
|
228
229
|
}
|
229
230
|
}
|
230
|
-
if (arg == cb_sym_document
|
231
|
-
bucket->
|
232
|
-
|
231
|
+
if (arg == cb_sym_document) {
|
232
|
+
cb_bucket_transcoder_set(bucket->self, cb_mDocument);
|
233
|
+
} else if (arg == cb_sym_marshal) {
|
234
|
+
cb_bucket_transcoder_set(bucket->self, cb_mMarshal);
|
235
|
+
} else if (arg == cb_sym_plain) {
|
236
|
+
cb_bucket_transcoder_set(bucket->self, cb_mPlain);
|
233
237
|
}
|
234
238
|
}
|
235
|
-
arg =
|
239
|
+
arg = rb_hash_lookup2(opts, cb_sym_transcoder, Qundef);
|
240
|
+
if (arg != Qundef) {
|
241
|
+
cb_bucket_transcoder_set(bucket->self, arg);
|
242
|
+
}
|
236
243
|
if (arg != Qnil) {
|
237
244
|
if (arg == cb_sym_production || arg == cb_sym_development) {
|
238
245
|
bucket->environment = arg;
|
@@ -269,6 +276,13 @@ do_scan_connection_options(struct cb_bucket_st *bucket, int argc, VALUE *argv)
|
|
269
276
|
}
|
270
277
|
}
|
271
278
|
bucket->async = RTEST(rb_hash_aref(opts, cb_sym_async));
|
279
|
+
arg = rb_hash_aref(opts, cb_sym_transcoder);
|
280
|
+
if (arg != Qnil) {
|
281
|
+
bucket->default_arith_create = RTEST(arg);
|
282
|
+
if (TYPE(arg) == T_FIXNUM) {
|
283
|
+
bucket->default_arith_init = NUM2ULL(arg);
|
284
|
+
}
|
285
|
+
}
|
272
286
|
} else {
|
273
287
|
opts = Qnil;
|
274
288
|
}
|
@@ -448,7 +462,7 @@ cb_bucket_alloc(VALUE klass)
|
|
448
462
|
* instead.
|
449
463
|
* @option options [String] :password (nil) the password of the user.
|
450
464
|
* @option options [true, false] :quiet (false) the flag controlling if raising
|
451
|
-
* exception when the client executes operations on
|
465
|
+
* exception when the client executes operations on non-existent keys. If it
|
452
466
|
* is +true+ it will raise {Couchbase::Error::NotFound} exceptions. The
|
453
467
|
* default behaviour is to return +nil+ value silently (might be useful in
|
454
468
|
* Rails cache).
|
@@ -494,8 +508,8 @@ cb_bucket_alloc(VALUE klass)
|
|
494
508
|
* @example Use list of nodes, in case some nodes might be dead
|
495
509
|
* Couchbase.new(:node_list => ['example.com:8091', 'example.org:8091', 'example.net'])
|
496
510
|
*
|
497
|
-
* @raise [Couchbase::Error::BucketNotFound] if there no such bucket to
|
498
|
-
* connect
|
511
|
+
* @raise [Couchbase::Error::BucketNotFound] if there is no such bucket to
|
512
|
+
* connect to
|
499
513
|
*
|
500
514
|
* @raise [Couchbase::Error::Connect] if the socket wasn't accessible
|
501
515
|
* (doesn't accept connections or doesn't respond in time)
|
@@ -506,7 +520,6 @@ cb_bucket_alloc(VALUE klass)
|
|
506
520
|
cb_bucket_init(int argc, VALUE *argv, VALUE self)
|
507
521
|
{
|
508
522
|
struct cb_bucket_st *bucket = DATA_PTR(self);
|
509
|
-
|
510
523
|
bucket->self = self;
|
511
524
|
bucket->exception = Qnil;
|
512
525
|
bucket->type = LCB_TYPE_BUCKET;
|
@@ -521,7 +534,7 @@ cb_bucket_init(int argc, VALUE *argv, VALUE self)
|
|
521
534
|
bucket->quiet = 0;
|
522
535
|
bucket->default_ttl = 0;
|
523
536
|
bucket->default_flags = 0;
|
524
|
-
|
537
|
+
cb_bucket_transcoder_set(self, cb_mDocument);
|
525
538
|
bucket->default_observe_timeout = 2500000;
|
526
539
|
bucket->on_error_proc = Qnil;
|
527
540
|
bucket->on_connect_proc = Qnil;
|
@@ -578,7 +591,7 @@ cb_bucket_init_copy(VALUE copy, VALUE orig)
|
|
578
591
|
copy_b->engine = orig_b->engine;
|
579
592
|
copy_b->async = orig_b->async;
|
580
593
|
copy_b->quiet = orig_b->quiet;
|
581
|
-
copy_b->
|
594
|
+
copy_b->transcoder = orig_b->transcoder;
|
582
595
|
copy_b->default_flags = orig_b->default_flags;
|
583
596
|
copy_b->default_ttl = orig_b->default_ttl;
|
584
597
|
copy_b->environment = orig_b->environment;
|
@@ -707,23 +720,49 @@ cb_bucket_default_flags_set(VALUE self, VALUE val)
|
|
707
720
|
struct cb_bucket_st *bucket = DATA_PTR(self);
|
708
721
|
|
709
722
|
bucket->default_flags = (uint32_t)NUM2ULONG(val);
|
710
|
-
bucket->default_format = cb_flags_get_format(bucket->default_flags);
|
711
723
|
return val;
|
712
724
|
}
|
713
725
|
|
714
726
|
VALUE
|
715
|
-
|
727
|
+
cb_bucket_transcoder_get(VALUE self)
|
716
728
|
{
|
717
729
|
struct cb_bucket_st *bucket = DATA_PTR(self);
|
718
|
-
return bucket->
|
730
|
+
return bucket->transcoder;
|
719
731
|
}
|
720
732
|
|
721
733
|
VALUE
|
722
|
-
|
734
|
+
cb_bucket_transcoder_set(VALUE self, VALUE val)
|
723
735
|
{
|
724
736
|
struct cb_bucket_st *bucket = DATA_PTR(self);
|
725
737
|
|
738
|
+
if (val != Qnil && !rb_respond_to(val, cb_id_dump) && !rb_respond_to(val, cb_id_load)) {
|
739
|
+
rb_raise(rb_eArgError, "transcoder must respond to dump and load methods");
|
740
|
+
}
|
741
|
+
bucket->transcoder = val;
|
742
|
+
|
743
|
+
return bucket->transcoder;
|
744
|
+
}
|
745
|
+
|
746
|
+
VALUE
|
747
|
+
cb_bucket_default_format_get(VALUE self)
|
748
|
+
{
|
749
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
750
|
+
|
751
|
+
if (bucket->transcoder == cb_mDocument) {
|
752
|
+
return cb_sym_document;
|
753
|
+
} else if (bucket->transcoder == cb_mMarshal) {
|
754
|
+
return cb_sym_marshal;
|
755
|
+
} else if (bucket->transcoder == cb_mPlain) {
|
756
|
+
return cb_sym_plain;
|
757
|
+
}
|
758
|
+
return Qnil;
|
759
|
+
}
|
760
|
+
|
761
|
+
VALUE
|
762
|
+
cb_bucket_default_format_set(VALUE self, VALUE val)
|
763
|
+
{
|
726
764
|
if (TYPE(val) == T_FIXNUM) {
|
765
|
+
rb_warn("numeric argument to #default_format option is deprecated, use symbol");
|
727
766
|
switch (FIX2INT(val)) {
|
728
767
|
case CB_FMT_DOCUMENT:
|
729
768
|
val = cb_sym_document;
|
@@ -736,9 +775,14 @@ cb_bucket_default_format_set(VALUE self, VALUE val)
|
|
736
775
|
break;
|
737
776
|
}
|
738
777
|
}
|
739
|
-
if (val == cb_sym_document
|
740
|
-
|
741
|
-
|
778
|
+
if (val == cb_sym_document) {
|
779
|
+
cb_bucket_transcoder_set(self, cb_mDocument);
|
780
|
+
} else if (val == cb_sym_marshal) {
|
781
|
+
cb_bucket_transcoder_set(self, cb_mMarshal);
|
782
|
+
} else if (val == cb_sym_plain) {
|
783
|
+
cb_bucket_transcoder_set(self, cb_mPlain);
|
784
|
+
} else {
|
785
|
+
rb_raise(rb_eArgError, "unknown format");
|
742
786
|
}
|
743
787
|
|
744
788
|
return val;
|
@@ -1103,9 +1147,9 @@ cb_bucket_inspect(VALUE self)
|
|
1103
1147
|
rb_str_append(str, bucket->pool);
|
1104
1148
|
rb_str_buf_cat2(str, "/buckets/");
|
1105
1149
|
rb_str_append(str, bucket->bucket);
|
1106
|
-
rb_str_buf_cat2(str, "
|
1107
|
-
|
1108
|
-
|
1150
|
+
rb_str_buf_cat2(str, "/\" transcoder=");
|
1151
|
+
rb_str_append(str, rb_inspect(bucket->transcoder));
|
1152
|
+
snprintf(buf, 150, ", default_flags=0x%x, quiet=%s, connected=%s, timeout=%u",
|
1109
1153
|
bucket->default_flags,
|
1110
1154
|
bucket->quiet ? "true" : "false",
|
1111
1155
|
(bucket->handle && bucket->connected) ? "true" : "false",
|
data/ext/couchbase_ext/context.c
CHANGED
@@ -25,7 +25,8 @@ cb_context_mark(void *p, struct cb_bucket_st* bucket)
|
|
25
25
|
rb_gc_mark(ctx->rv);
|
26
26
|
rb_gc_mark(ctx->exception);
|
27
27
|
rb_gc_mark(ctx->observe_options);
|
28
|
-
rb_gc_mark(ctx->
|
28
|
+
rb_gc_mark(ctx->transcoder);
|
29
|
+
rb_gc_mark(ctx->transcoder_opts);
|
29
30
|
rb_gc_mark(ctx->operation);
|
30
31
|
rb_gc_mark(ctx->headers_val);
|
31
32
|
(void)bucket;
|
@@ -27,8 +27,10 @@ VALUE cb_cTimer;
|
|
27
27
|
/* Modules */
|
28
28
|
VALUE cb_mCouchbase;
|
29
29
|
VALUE cb_mError;
|
30
|
+
VALUE cb_mTranscoder;
|
31
|
+
VALUE cb_mDocument;
|
32
|
+
VALUE cb_mPlain;
|
30
33
|
VALUE cb_mMarshal;
|
31
|
-
VALUE cb_mMultiJson;
|
32
34
|
VALUE cb_mURI;
|
33
35
|
VALUE em_m;
|
34
36
|
|
@@ -62,6 +64,7 @@ ID cb_sym_eventmachine;
|
|
62
64
|
ID cb_sym_extended;
|
63
65
|
ID cb_sym_flags;
|
64
66
|
ID cb_sym_format;
|
67
|
+
ID cb_sym_forced;
|
65
68
|
ID cb_sym_found;
|
66
69
|
ID cb_sym_get;
|
67
70
|
ID cb_sym_hostname;
|
@@ -97,6 +100,7 @@ ID cb_sym_set;
|
|
97
100
|
ID cb_sym_stats;
|
98
101
|
ID cb_sym_timeout;
|
99
102
|
ID cb_sym_touch;
|
103
|
+
ID cb_sym_transcoder;
|
100
104
|
ID cb_sym_ttl;
|
101
105
|
ID cb_sym_type;
|
102
106
|
ID cb_sym_unlock;
|
@@ -201,10 +205,12 @@ Init_couchbase_ext(void)
|
|
201
205
|
/* just a holder for EventMachine module */
|
202
206
|
em_m = 0;
|
203
207
|
|
204
|
-
cb_mMultiJson = rb_const_get(rb_cObject, rb_intern("MultiJson"));
|
205
208
|
cb_mURI = rb_const_get(rb_cObject, rb_intern("URI"));
|
206
|
-
cb_mMarshal = rb_const_get(rb_cObject, rb_intern("Marshal"));
|
207
209
|
cb_mCouchbase = rb_define_module("Couchbase");
|
210
|
+
cb_mTranscoder = rb_const_get(cb_mCouchbase, rb_intern("Transcoder"));
|
211
|
+
cb_mDocument = rb_const_get(cb_mTranscoder, rb_intern("Document"));
|
212
|
+
cb_mMarshal = rb_const_get(cb_mTranscoder, rb_intern("Marshal"));
|
213
|
+
cb_mPlain = rb_const_get(cb_mTranscoder, rb_intern("Plain"));
|
208
214
|
|
209
215
|
cb_mError = rb_define_module_under(cb_mCouchbase, "Error");
|
210
216
|
/* Document-class: Couchbase::Error::Base
|
@@ -285,8 +291,6 @@ Init_couchbase_ext(void)
|
|
285
291
|
/* Document-class: Couchbase::Error::NoMemory
|
286
292
|
* Out of memory error (on Server)
|
287
293
|
*
|
288
|
-
* The client ran out of memory
|
289
|
-
*
|
290
294
|
* @since 1.0.0
|
291
295
|
*/
|
292
296
|
cb_eNoMemoryError = rb_define_class_under(cb_mError, "NoMemory", cb_eBaseError);
|
@@ -761,6 +765,50 @@ Init_couchbase_ext(void)
|
|
761
765
|
rb_define_method(cb_cBucket, "default_flags", cb_bucket_default_flags_get, 0);
|
762
766
|
rb_define_method(cb_cBucket, "default_flags=", cb_bucket_default_flags_set, 1);
|
763
767
|
|
768
|
+
/* Document-method: transcoder
|
769
|
+
* Set data transcoder for the current connection
|
770
|
+
*
|
771
|
+
* @since 1.2.4
|
772
|
+
*
|
773
|
+
* It is possible to define custom transcoder to handle all value
|
774
|
+
* transformation, for example, if you need to adopt legacy
|
775
|
+
* application. The transcoder should respond to two methods:
|
776
|
+
* +dump+ and +load+. They are accepting the data itself, the
|
777
|
+
* flags field, and the options hash from the library.
|
778
|
+
*
|
779
|
+
* @example Simple data transcoder, which use Zlib to compress documents
|
780
|
+
* class ZlibTranscoder
|
781
|
+
* FMT_ZLIB = 0x04
|
782
|
+
*
|
783
|
+
* def initialize(base)
|
784
|
+
* @base = base
|
785
|
+
* end
|
786
|
+
*
|
787
|
+
* def dump(obj, flags, options = {})
|
788
|
+
* obj, flags = @base.dump(obj, flags, options)
|
789
|
+
* z = Zlib::Deflate.new(Zlib::BEST_SPEED)
|
790
|
+
* buffer = z.deflate(obj, Zlib::FINISH)
|
791
|
+
* z.close
|
792
|
+
* [buffer, flags|FMT_ZLIB]
|
793
|
+
* end
|
794
|
+
*
|
795
|
+
* def load(blob, flags, options = {})
|
796
|
+
* # decompress value only if Zlib flag set
|
797
|
+
* if (flags & FMT_ZLIB) == FMT_ZLIB
|
798
|
+
* z = Zlib::Inflate.new
|
799
|
+
* blob = z.inflate(blob)
|
800
|
+
* z.finish
|
801
|
+
* z.close
|
802
|
+
* end
|
803
|
+
* @base.load(blob, flags, options)
|
804
|
+
* end
|
805
|
+
* end
|
806
|
+
*
|
807
|
+
* @return [Object] the data transcoder */
|
808
|
+
/* rb_define_attr(cb_cBucket, "transcoder", 1, 1); */
|
809
|
+
rb_define_method(cb_cBucket, "transcoder", cb_bucket_transcoder_get, 0);
|
810
|
+
rb_define_method(cb_cBucket, "transcoder=", cb_bucket_transcoder_set, 1);
|
811
|
+
|
764
812
|
/* Document-method: default_format
|
765
813
|
* Default format for new values.
|
766
814
|
*
|
@@ -789,11 +837,11 @@ Init_couchbase_ext(void)
|
|
789
837
|
* your ruby object with standard <tt>Marshal.dump</tt> and
|
790
838
|
* <tt>Marhal.load</tt> methods.
|
791
839
|
*
|
792
|
-
* @example Selecting plain format using
|
793
|
-
* connection.
|
840
|
+
* @example Selecting 'plain' format using symbol
|
841
|
+
* connection.default_format = :plain
|
794
842
|
*
|
795
|
-
* @example Selecting plain format using Fixnum constant
|
796
|
-
* connection.
|
843
|
+
* @example Selecting plain format using Fixnum constant (deprecated)
|
844
|
+
* connection.default_format = Couchbase::Bucket::FMT_PLAIN
|
797
845
|
*
|
798
846
|
* @note Amending default_format will also change #default_flags value
|
799
847
|
*
|
@@ -1130,6 +1178,7 @@ Init_couchbase_ext(void)
|
|
1130
1178
|
cb_sym_extended = ID2SYM(rb_intern("extended"));
|
1131
1179
|
cb_sym_flags = ID2SYM(rb_intern("flags"));
|
1132
1180
|
cb_sym_format = ID2SYM(rb_intern("format"));
|
1181
|
+
cb_sym_forced = ID2SYM(rb_intern("forced"));
|
1133
1182
|
cb_sym_found = ID2SYM(rb_intern("found"));
|
1134
1183
|
cb_sym_get = ID2SYM(rb_intern("get"));
|
1135
1184
|
cb_sym_hostname = ID2SYM(rb_intern("hostname"));
|
@@ -1165,6 +1214,7 @@ Init_couchbase_ext(void)
|
|
1165
1214
|
cb_sym_stats = ID2SYM(rb_intern("stats"));
|
1166
1215
|
cb_sym_timeout = ID2SYM(rb_intern("timeout"));
|
1167
1216
|
cb_sym_touch = ID2SYM(rb_intern("touch"));
|
1217
|
+
cb_sym_transcoder = ID2SYM(rb_intern("transcoder"));
|
1168
1218
|
cb_sym_ttl = ID2SYM(rb_intern("ttl"));
|
1169
1219
|
cb_sym_type = ID2SYM(rb_intern("type"));
|
1170
1220
|
cb_sym_unlock = ID2SYM(rb_intern("unlock"));
|