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:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#casFixnum (readonly)

Returns:

  • (Fixnum)

Since:

  • 1.0.0

#completedBoolean (readonly) Also known as: completed?

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

Returns:

  • (Boolean)

#errorCouchbase::Error::Base (readonly)

Returns:

Since:

  • 1.0.0

#flagsFixnum (readonly)

Returns:

  • (Fixnum)

Since:

  • 1.0.0

#from_masterBoolean (readonly) Also known as: from_master?

True if key stored on master

Returns:

  • (Boolean)

See Also:

Since:

  • 1.2.0.dp6

#headersHash (readonly)

HTTP headers

Returns:

  • (Hash)

Since:

  • 1.2.0

#keyString (readonly)

Returns:

Since:

  • 1.0.0

#nodeString (readonly)

Returns:

Since:

  • 1.0.0

#operationSymbol (readonly)

Returns:

  • (Symbol)

Since:

  • 1.0.0

#statusSymbol (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

Returns:

  • (Symbol)

See Also:

Since:

  • 1.2.0.dp6

#time_to_persistFixnum (readonly) Also known as: ttp

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

Returns:

  • (Fixnum)

See Also:

Since:

  • 1.2.0.dp6

#time_to_replicateFixnum (readonly) Also known as: ttr

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

Returns:

  • (Fixnum)

See Also:

Since:

  • 1.2.0.dp6

#valueString (readonly) Also known as: bucket

Returns:

Since:

  • 1.0.0

Instance Method Details

#inspectString

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

Returns:

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

#success?true, false

Check if result of operation was successful.

Returns:

  • (true, false)

    false if there is an error object attached, false otherwise.

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

#to_sString

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

Returns:

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