Class: Couchbase::Result

Inherits:
Object
  • Object
show all
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

Since:

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Result) initialize(attrs = {})



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

- (Fixnum) cas (readonly)

Since:

  • 1.0.0

- (Boolean) completed (readonly) Also known as: completed?

In Bucket::CouchRequest operations used to mark the final call

- (Couchbase::Error::Base) error (readonly)

Since:

  • 1.0.0

- (Fixnum) flags (readonly)

Since:

  • 1.0.0

- (Boolean) from_master (readonly) Also known as: from_master?

True if key stored on master

See Also:

Since:

  • 1.2.0.dp6

- (Hash) headers (readonly)

HTTP headers

Since:

  • 1.2.0

- (String) key (readonly)

Since:

  • 1.0.0

- (String) node (readonly)

Since:

  • 1.0.0

- (Symbol) operation (readonly)

Since:

  • 1.0.0

- (Symbol) status (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

See Also:

Since:

  • 1.2.0.dp6

- (Fixnum) time_to_persist (readonly) Also known as: ttp

Average time needed to persist key on the disk (zero if unavailable)

See Also:

Since:

  • 1.2.0.dp6

- (Fixnum) time_to_replicate (readonly) Also known as: ttr

Average time needed to replicate key on the disk (zero if unavailable)

See Also:

Since:

  • 1.2.0.dp6

- (String) value (readonly) Also known as: bucket

Since:

  • 1.0.0

Instance Method Details

- (String) inspect

Returns a string containing a human-readable representation of the Result.

Since:

  • 1.0.0



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;
}

- (true, ...) success?

Check if result of operation was successful.

Since:

  • 1.0.0



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;
}

- (String) to_s

Returns a string containing a human-readable representation of the Result.

Since:

  • 1.0.0



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;
}