Class: Groonga::Object
- Inherits:
-
Object
- Object
- Groonga::Object
- Defined in:
- ext/rb-grn-object.c,
ext/rb-grn-object.c
Overview
Ruby/groongaが提供するクラスのベースとなるクラス。 Groonga::ContextとGroonga::Logger以外はGroonga::Objectを継 承している。
Direct Known Subclasses
Instance Method Summary collapse
-
#== ⇒ Object
call-seq: object == other -> true/false.
-
#[] ⇒ Object
call-seq: object -> 値.
-
#[]= ⇒ Object
call-seq: object = value.
-
#append ⇒ Object
call-seq: object.append(id, value).
-
#close ⇒ Object
call-seq: object.close.
-
#closed? ⇒ Boolean
call-seq: object.closed? -> true/false.
-
#domain ⇒ Object
call-seq: object.domain -> Groonga::Object/nil.
-
#id ⇒ Object
call-seq: object.id -> ID/nil.
-
#inspect ⇒ Object
call-seq: object.inspect -> 詳細情報.
-
#name ⇒ Object
call-seq: object.name -> 名前/nil.
-
#path ⇒ Object
call-seq: object.path -> ファイルパス/nil.
-
#persistent? ⇒ Boolean
call-seq: object.persistent? -> true/false.
-
#prepend ⇒ Object
call-seq: object.prepend(id, value).
-
#range ⇒ Object
call-seq: object.range -> Groonga::Object/nil.
-
#remove ⇒ Object
call-seq: object.remove.
-
#temporary? ⇒ Boolean
call-seq: object.temporary? -> true/false.
Instance Method Details
#== ⇒ Object
call-seq:
object == other -> true/false
objectとotherが同じgroongaのオブジェクトならtrue
を返 し、そうでなければfalse
を返す。
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 |
# File 'ext/rb-grn-object.c', line 1053
static VALUE
rb_grn_object_equal (VALUE self, VALUE other)
{
RbGrnObject *self_rb_grn_object, *other_rb_grn_object;
if (self == other)
return Qtrue;
if (!RVAL2CBOOL(rb_funcall(rb_obj_class(self), rb_intern("=="), 1,
rb_obj_class(other))))
return Qfalse;
self_rb_grn_object = SELF(self);
other_rb_grn_object = SELF(other);
return self_rb_grn_object->object == other_rb_grn_object->object;
}
|
#[] ⇒ Object
call-seq:
object[id] -> 値
objectのidに対応する値を返す。
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 |
# File 'ext/rb-grn-object.c', line 1079
VALUE
rb_grn_object_array_reference (VALUE self, VALUE rb_id)
{
VALUE exception;
RbGrnObject *rb_grn_object;
grn_id id, range_id;
grn_ctx *context;
grn_obj *object;
grn_obj *range;
unsigned char range_type;
grn_obj value;
VALUE rb_value = Qnil;
rb_grn_object = SELF(self);
context = rb_grn_object->context;
object = rb_grn_object->object;
if (!object)
return Qnil;
id = NUM2UINT(rb_id);
range_id = grn_obj_get_range(context, object);
range = grn_ctx_at(context, range_id);
range_type = range ? range->header.type : GRN_VOID;
switch (object->header.type) {
case GRN_TABLE_HASH_KEY:
case GRN_TABLE_PAT_KEY:
case GRN_TABLE_NO_KEY:
GRN_OBJ_INIT(&value, GRN_BULK, 0, GRN_ID_NIL);
break;
case GRN_TYPE:
case GRN_ACCESSOR: /* FIXME */
GRN_OBJ_INIT(&value, GRN_BULK, 0, range_id);
break;
case GRN_COLUMN_VAR_SIZE:
case GRN_COLUMN_FIX_SIZE:
switch (object->header.flags & GRN_OBJ_COLUMN_TYPE_MASK) {
case GRN_OBJ_COLUMN_VECTOR:
GRN_OBJ_INIT(&value, GRN_VECTOR, 0, range_id);
break;
case GRN_OBJ_COLUMN_SCALAR:
GRN_OBJ_INIT(&value, GRN_BULK, 0, range_id);
break;
default:
rb_raise(rb_eGrnError, "unsupported column type: %u: %s",
range_type, rb_grn_inspect(self));
break;
}
break;
case GRN_COLUMN_INDEX:
GRN_UINT32_INIT(&value, 0);
break;
default:
rb_raise(rb_eGrnError,
"unsupported type: %s", rb_grn_inspect(self));
break;
}
grn_obj_get_value(context, object, id, &value);
exception = rb_grn_context_to_exception(context, self);
if (NIL_P(exception))
rb_value = GRNVALUE2RVAL(context, &value, range, self);
grn_obj_close(context, &value);
if (!NIL_P(exception))
rb_exc_raise(exception);
return rb_value;
}
|
#[]= ⇒ Object
call-seq:
object[id] = value
objectのidに対応する値を設定する。既存の値は上書きさ れる。
1241 1242 1243 1244 1245 |
# File 'ext/rb-grn-object.c', line 1241
static VALUE
rb_grn_object_array_set (VALUE self, VALUE rb_id, VALUE rb_value)
{
return rb_grn_object_set(self, rb_id, rb_value, GRN_OBJ_SET);
}
|
#append ⇒ Object
call-seq:
object.append(id, value)
objectのidに対応する値の最後にvalueを追加する。
1255 1256 1257 1258 1259 |
# File 'ext/rb-grn-object.c', line 1255
static VALUE
rb_grn_object_append_value (VALUE self, VALUE rb_id, VALUE rb_value)
{
return rb_grn_object_set(self, rb_id, rb_value, GRN_OBJ_APPEND);
}
|
#close ⇒ Object
call-seq:
object.close
objectが使用しているリソースを開放する。これ以降objectを 使うことはできない。
462 463 464 465 466 467 468 469 470 471 472 473 |
# File 'ext/rb-grn-object.c', line 462
VALUE
rb_grn_object_close (VALUE self)
{
grn_obj *object;
grn_ctx *context;
rb_grn_object_deconstruct(SELF(self), &object, &context,
NULL, NULL, NULL, NULL);
if (object && context)
grn_obj_close(context, object);
return Qnil;
}
|
#closed? ⇒ Boolean
call-seq:
object.closed? -> true/false
objectが開放済みの場合はtrue
を返し、そうでない場合は false
を返す。
484 485 486 487 488 489 490 491 492 493 494 495 |
# File 'ext/rb-grn-object.c', line 484
VALUE
rb_grn_object_closed_p (VALUE self)
{
RbGrnObject *rb_grn_object;
rb_grn_object = SELF(self);
if (rb_grn_object->context && rb_grn_object->object) {
return Qfalse;
} else {
return Qtrue;
}
}
|
#domain ⇒ Object
call-seq:
object.domain -> Groonga::Object/nil
objectの属しているGroonga::Objectを返す。例えば、 Groonga::ColumnはGroonga::Tableを返す。属している Groonga::Objectがない場合はnil
を返す。
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 |
# File 'ext/rb-grn-object.c', line 945
static VALUE
rb_grn_object_get_domain (VALUE self)
{
RbGrnObject *rb_grn_object;
grn_ctx *context;
grn_obj *object;
grn_id domain;
rb_grn_object = SELF(self);
object = rb_grn_object->object;
if (!object)
return Qnil;
context = rb_grn_object->context;
domain = object->header.domain;
if (domain == GRN_ID_NIL) {
return Qnil;
} else {
grn_obj *domain_object;
domain_object = grn_ctx_at(context, domain);
if (domain_object)
return GRNOBJECT2RVAL(Qnil, context, domain_object, RB_GRN_FALSE);
else
return UINT2NUM(domain);
}
}
|
#id ⇒ Object
call-seq:
object.id -> ID/nil
objectのIDを返す。objectが#closed?なときやIDがない場合 はnil
を返す。
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 |
# File 'ext/rb-grn-object.c', line 849
VALUE
rb_grn_object_get_id (VALUE self)
{
RbGrnObject *rb_grn_object;
grn_id id;
rb_grn_object = SELF(self);
if (!rb_grn_object->object)
return Qnil;
id = grn_obj_id(rb_grn_object->context, rb_grn_object->object);
if (id == GRN_ID_NIL)
return Qnil;
else
return UINT2NUM(id);
}
|
#inspect ⇒ Object
call-seq:
object.inspect -> 詳細情報
objectの詳細を示した文字列を返す。デバッグ用。
827 828 829 830 831 832 833 834 835 836 837 838 |
# File 'ext/rb-grn-object.c', line 827
static VALUE
rb_grn_object_inspect (VALUE self)
{
VALUE inspected;
inspected = rb_str_new2("");
rb_grn_object_inspect_header(self, inspected);
rb_grn_object_inspect_content(self, inspected);
rb_grn_object_inspect_footer(self, inspected);
return inspected;
}
|
#name ⇒ Object
call-seq:
object.name -> 名前/nil
objectの名前を返す。無名オブジェクトの場合はnil
を返す。
981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 |
# File 'ext/rb-grn-object.c', line 981
static VALUE
rb_grn_object_get_name (VALUE self)
{
RbGrnObject *rb_grn_object;
VALUE rb_name;
int name_size;
rb_grn_object = SELF(self);
if (!rb_grn_object->object)
return Qnil;
name_size = grn_obj_name(rb_grn_object->context, rb_grn_object->object,
NULL, 0);
if (name_size == 0)
return Qnil;
rb_name = rb_str_buf_new(name_size);
rb_str_set_len(rb_name, name_size);
grn_obj_name(rb_grn_object->context, rb_grn_object->object,
RSTRING_PTR(rb_name), name_size);
return rb_name;
}
|
#path ⇒ Object
call-seq:
object.path -> ファイルパス/nil
objectに対応するファイルパスを返す。一時object ならnil
を返す。
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 |
# File 'ext/rb-grn-object.c', line 875
static VALUE
rb_grn_object_get_path (VALUE self)
{
RbGrnObject *rb_grn_object;
const char *path;
rb_grn_object = SELF(self);
if (!rb_grn_object->object)
return Qnil;
path = grn_obj_path(rb_grn_object->context, rb_grn_object->object);
if (!path)
return Qnil;
else
return rb_str_new2(path);
}
|
#persistent? ⇒ Boolean
call-seq:
object.persistent? -> true/false
objectが永続オブジェクトならtrue
、一時オブジェクトな らfalse
を返す。
923 924 925 926 927 928 929 930 931 932 933 |
# File 'ext/rb-grn-object.c', line 923
static VALUE
rb_grn_object_persistent_p (VALUE self)
{
RbGrnObject *rb_grn_object;
rb_grn_object = SELF(self);
if (!rb_grn_object->object)
return Qnil;
return rb_grn_object->object->header.flags & GRN_OBJ_PERSISTENT;
}
|
#prepend ⇒ Object
call-seq:
object.prepend(id, value)
objectのidに対応する値の最初にvalueを追加する。
1269 1270 1271 1272 1273 |
# File 'ext/rb-grn-object.c', line 1269
static VALUE
rb_grn_object_prepend_value (VALUE self, VALUE rb_id, VALUE rb_value)
{
return rb_grn_object_set(self, rb_id, rb_value, GRN_OBJ_PREPEND);
}
|
#range ⇒ Object
call-seq:
object.range -> Groonga::Object/nil
objectの値がとりうる範囲を示したGroonga::Objectを返す。 例えば、Groonga::Columnの場合は Groonga::Table#define_columnで指定されたGroonga::Typeや Groonga::Tableを返す。 範囲が指定されていないオブジェクトの場合はnil
を返す。
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 |
# File 'ext/rb-grn-object.c', line 1016
static VALUE
rb_grn_object_get_range (VALUE self)
{
RbGrnObject *rb_grn_object;
grn_ctx *context;
grn_obj *object;
grn_id range;
rb_grn_object = SELF(self);
object = rb_grn_object->object;
if (!object)
return Qnil;
context = rb_grn_object->context;
range = grn_obj_get_range(context, object);
if (range == GRN_ID_NIL) {
return Qnil;
} else {
grn_obj *range_object;
range_object = grn_ctx_at(context, range);
if (range_object)
return GRNOBJECT2RVAL(Qnil, context, range_object, RB_GRN_FALSE);
else
return UINT2NUM(range);
}
}
|
#remove ⇒ Object
call-seq:
object.remove
objectをメモリから解放し、それが永続オブジェクトであっ た場合は、該当するファイル一式を削除する。
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 |
# File 'ext/rb-grn-object.c', line 1284
static VALUE
rb_grn_object_remove (VALUE self)
{
RbGrnObject *rb_grn_object;
grn_ctx *context;
grn_rc rc;
rb_grn_object = SELF(self);
if (!rb_grn_object->object)
return Qnil;
context = rb_grn_object->context;
rc = grn_obj_remove(context, rb_grn_object->object);
rb_grn_rc_check(rc, self);
rb_iv_set(self, "@context", Qnil);
return Qnil;
}
|
#temporary? ⇒ Boolean
call-seq:
object.temporary? -> true/false
objectが一時オブジェクトならtrue
、永続オブジェクトな らfalse
を返す。
902 903 904 905 906 907 908 909 910 911 912 |
# File 'ext/rb-grn-object.c', line 902
static VALUE
rb_grn_object_temporary_p (VALUE self)
{
RbGrnObject *rb_grn_object;
rb_grn_object = SELF(self);
if (!rb_grn_object->object)
return Qnil;
return !(rb_grn_object->object->header.flags & GRN_OBJ_PERSISTENT);
}
|