Class: Couchbase::Result
- Inherits:
-
Object
- Object
- Couchbase::Result
- Defined in:
- ext/couchbase_ext/couchbase_ext.c,
lib/couchbase/result.rb,
ext/couchbase_ext/couchbase_ext.c
Overview
The object which yielded to asynchronous callbacks
Instance Attribute Summary collapse
- #cas ⇒ Fixnum readonly
-
#completed ⇒ Boolean
(also: #completed?)
readonly
In Bucket::CouchRequest operations used to mark the final call.
- #error ⇒ Couchbase::Error::Base readonly
- #flags ⇒ Fixnum readonly
-
#from_master ⇒ Boolean
(also: #from_master?)
readonly
True if key stored on master.
-
#headers ⇒ Hash
readonly
HTTP headers.
- #key ⇒ String readonly
- #node ⇒ String readonly
- #operation ⇒ Symbol readonly
-
#status ⇒ Symbol
readonly
Status of the key.
-
#time_to_persist ⇒ Fixnum
(also: #ttp)
readonly
Average time needed to persist key on the disk (zero if unavailable).
-
#time_to_replicate ⇒ Fixnum
(also: #ttr)
readonly
Average time needed to replicate key on the disk (zero if unavailable).
- #value ⇒ String (also: #bucket) readonly
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Result
constructor
A new instance of Result.
-
#inspect ⇒ String
Returns a string containing a human-readable representation of the Result.
-
#success? ⇒ true, false
Check if result of operation was successful.
-
#to_s ⇒ String
Returns a string containing a human-readable representation of the Result.
Constructor Details
#initialize(attrs = {}) ⇒ Result
Returns a new instance of Result.
20 21 22 23 24 |
# File 'lib/couchbase/result.rb', line 20 def initialize(attrs = {}) attrs.each do |k, v| instance_variable_set("@#{k}", v) if respond_to?(k) end end |
Instance Attribute Details
#cas ⇒ Fixnum (readonly)
#completed ⇒ Boolean (readonly) Also known as: completed?
In Bucket::CouchRequest operations used to mark the final call
#error ⇒ Couchbase::Error::Base (readonly)
#flags ⇒ Fixnum (readonly)
#from_master ⇒ Boolean (readonly) Also known as: from_master?
True if key stored on master
#headers ⇒ Hash (readonly)
HTTP headers
#key ⇒ String (readonly)
#node ⇒ String (readonly)
#operation ⇒ Symbol (readonly)
#status ⇒ Symbol (readonly)
Status of the key. Possible values:
:found
-
Key found in cache, but not yet persisted
:persisted
-
Key found and persisted
:not_found
-
Key not found
#time_to_persist ⇒ Fixnum (readonly) Also known as: ttp
Average time needed to persist key on the disk (zero if unavailable)
#time_to_replicate ⇒ Fixnum (readonly) Also known as: ttr
Average time needed to replicate key on the disk (zero if unavailable)
#value ⇒ String (readonly) Also known as: bucket
Instance Method Details
#inspect ⇒ String
Returns a string containing a human-readable representation of the Result.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'ext/couchbase_ext/result.c', line 41
VALUE
cb_result_inspect(VALUE self)
{
VALUE str, attr;
char buf[100];
str = rb_str_buf_new2("#<");
rb_str_buf_cat2(str, rb_obj_classname(self));
snprintf(buf, 100, ":%p", (void *)self);
rb_str_buf_cat2(str, buf);
attr = rb_attr_get(self, cb_id_iv_operation);
if (RTEST(attr)) {
rb_str_buf_cat2(str, " operation=");
rb_str_append(str, rb_inspect(attr));
}
attr = rb_attr_get(self, cb_id_iv_error);
if (RTEST(attr)) {
rb_str_buf_cat2(str, " error=");
rb_str_append(str, rb_inspect(attr));
}
attr = rb_attr_get(self, cb_id_iv_value);
if (RTEST(attr) && RTEST(rb_obj_is_kind_of(attr, cb_cBucket))) {
rb_str_buf_cat2(str, " bucket="); /* value also accessible using alias #bucket */
rb_str_append(str, rb_inspect(attr));
}
attr = rb_attr_get(self, cb_id_iv_key);
if (RTEST(attr)) {
rb_str_buf_cat2(str, " key=");
rb_str_append(str, rb_inspect(attr));
}
attr = rb_attr_get(self, cb_id_iv_status);
if (RTEST(attr)) {
rb_str_buf_cat2(str, " status=");
rb_str_append(str, rb_inspect(attr));
}
attr = rb_attr_get(self, cb_id_iv_cas);
if (RTEST(attr)) {
rb_str_buf_cat2(str, " cas=");
rb_str_append(str, rb_inspect(attr));
}
attr = rb_attr_get(self, cb_id_iv_flags);
if (RTEST(attr)) {
rb_str_buf_cat2(str, " flags=0x");
rb_str_append(str, rb_funcall(attr, cb_id_to_s, 1, INT2FIX(16)));
}
attr = rb_attr_get(self, cb_id_iv_node);
if (RTEST(attr)) {
rb_str_buf_cat2(str, " node=");
rb_str_append(str, rb_inspect(attr));
}
attr = rb_attr_get(self, cb_id_iv_from_master);
if (attr != Qnil) {
rb_str_buf_cat2(str, " from_master=");
rb_str_append(str, rb_inspect(attr));
}
attr = rb_attr_get(self, cb_id_iv_time_to_persist);
if (RTEST(attr)) {
rb_str_buf_cat2(str, " time_to_persist=");
rb_str_append(str, rb_inspect(attr));
}
attr = rb_attr_get(self, cb_id_iv_time_to_replicate);
if (RTEST(attr)) {
rb_str_buf_cat2(str, " time_to_replicate=");
rb_str_append(str, rb_inspect(attr));
}
attr = rb_attr_get(self, cb_id_iv_headers);
if (RTEST(attr)) {
rb_str_buf_cat2(str, " headers=");
rb_str_append(str, rb_inspect(attr));
}
rb_str_buf_cat2(str, ">");
return str;
}
|
#success? ⇒ true, false
Check if result of operation was successful.
28 29 30 31 32 |
# File 'ext/couchbase_ext/result.c', line 28
VALUE
cb_result_success_p(VALUE self)
{
return RTEST(rb_attr_get(self, cb_id_iv_error)) ? Qfalse : Qtrue;
}
|
#to_s ⇒ String
Returns a string containing a human-readable representation of the Result.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'ext/couchbase_ext/result.c', line 41
VALUE
cb_result_inspect(VALUE self)
{
VALUE str, attr;
char buf[100];
str = rb_str_buf_new2("#<");
rb_str_buf_cat2(str, rb_obj_classname(self));
snprintf(buf, 100, ":%p", (void *)self);
rb_str_buf_cat2(str, buf);
attr = rb_attr_get(self, cb_id_iv_operation);
if (RTEST(attr)) {
rb_str_buf_cat2(str, " operation=");
rb_str_append(str, rb_inspect(attr));
}
attr = rb_attr_get(self, cb_id_iv_error);
if (RTEST(attr)) {
rb_str_buf_cat2(str, " error=");
rb_str_append(str, rb_inspect(attr));
}
attr = rb_attr_get(self, cb_id_iv_value);
if (RTEST(attr) && RTEST(rb_obj_is_kind_of(attr, cb_cBucket))) {
rb_str_buf_cat2(str, " bucket="); /* value also accessible using alias #bucket */
rb_str_append(str, rb_inspect(attr));
}
attr = rb_attr_get(self, cb_id_iv_key);
if (RTEST(attr)) {
rb_str_buf_cat2(str, " key=");
rb_str_append(str, rb_inspect(attr));
}
attr = rb_attr_get(self, cb_id_iv_status);
if (RTEST(attr)) {
rb_str_buf_cat2(str, " status=");
rb_str_append(str, rb_inspect(attr));
}
attr = rb_attr_get(self, cb_id_iv_cas);
if (RTEST(attr)) {
rb_str_buf_cat2(str, " cas=");
rb_str_append(str, rb_inspect(attr));
}
attr = rb_attr_get(self, cb_id_iv_flags);
if (RTEST(attr)) {
rb_str_buf_cat2(str, " flags=0x");
rb_str_append(str, rb_funcall(attr, cb_id_to_s, 1, INT2FIX(16)));
}
attr = rb_attr_get(self, cb_id_iv_node);
if (RTEST(attr)) {
rb_str_buf_cat2(str, " node=");
rb_str_append(str, rb_inspect(attr));
}
attr = rb_attr_get(self, cb_id_iv_from_master);
if (attr != Qnil) {
rb_str_buf_cat2(str, " from_master=");
rb_str_append(str, rb_inspect(attr));
}
attr = rb_attr_get(self, cb_id_iv_time_to_persist);
if (RTEST(attr)) {
rb_str_buf_cat2(str, " time_to_persist=");
rb_str_append(str, rb_inspect(attr));
}
attr = rb_attr_get(self, cb_id_iv_time_to_replicate);
if (RTEST(attr)) {
rb_str_buf_cat2(str, " time_to_replicate=");
rb_str_append(str, rb_inspect(attr));
}
attr = rb_attr_get(self, cb_id_iv_headers);
if (RTEST(attr)) {
rb_str_buf_cat2(str, " headers=");
rb_str_append(str, rb_inspect(attr));
}
rb_str_buf_cat2(str, ">");
return str;
}
|