[Groonga-commit] ranguba/rroonga at 77ea43e [master] Bind grn_config_delete()

Back to archive index

Masafumi Yokoyama null+****@clear*****
Sat Mar 5 12:35:07 JST 2016


Masafumi Yokoyama	2016-03-05 12:35:07 +0900 (Sat, 05 Mar 2016)

  New Revision: 77ea43e0e507d716a423ec5b44244ff70cf52f45
  https://github.com/ranguba/rroonga/commit/77ea43e0e507d716a423ec5b44244ff70cf52f45

  Merged 947b49c: Merge pull request #119 from ranguba/bind-grn_config_delete

  Message:
    Bind grn_config_delete()
    
    GitHub: #116

  Modified files:
    ext/groonga/rb-grn-config.c
    test/test-config.rb

  Modified: ext/groonga/rb-grn-config.c (+37 -0)
===================================================================
--- ext/groonga/rb-grn-config.c    2016-03-05 12:27:32 +0900 (e8d25c8)
+++ ext/groonga/rb-grn-config.c    2016-03-05 12:35:07 +0900 (ebc3904)
@@ -1,6 +1,7 @@
 /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /*
   Copyright (C) 2015-2016  Kouhei Sutou <kou �� clear-code.com>
+  Copyright (C) 2016  Masafumi Yokoyama <yokoyama �� clear-code.com>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -131,6 +132,40 @@ rb_grn_config_set (VALUE self, VALUE rb_key, VALUE rb_value)
     return rb_value_original;
 }
 
+/*
+ * Deletes a configuration for key.
+ *
+ * @overload delete(key)
+ *   @param [String] key The key.
+ *
+ * @since 6.0.0
+ */
+static VALUE
+rb_grn_config_delete (VALUE self, VALUE rb_key)
+{
+    VALUE rb_context;
+    grn_ctx *context;
+    const char *key;
+    int key_size;
+
+    rb_context = rb_iv_get(self, "@context");
+    context = rb_grn_context_ensure(&rb_context);
+
+    rb_key = rb_grn_convert_to_string(rb_key);
+    key = RSTRING_PTR(rb_key);
+    key_size = RSTRING_LEN(rb_key);
+
+    {
+        grn_rc rc;
+        rc = grn_config_delete(context,
+                            key, key_size);
+        rb_grn_context_check(context, self);
+        rb_grn_rc_check(rc, self);
+    }
+
+    return Qnil;
+}
+
 void
 rb_grn_init_config (VALUE mGrn)
 {
@@ -143,4 +178,6 @@ rb_grn_init_config (VALUE mGrn)
 
     rb_define_method(cGrnConfig, "[]", rb_grn_config_get, 1);
     rb_define_method(cGrnConfig, "[]=", rb_grn_config_set, 2);
+
+    rb_define_method(cGrnConfig, "delete", rb_grn_config_delete, 1);
 }

  Modified: test/test-config.rb (+10 -0)
===================================================================
--- test/test-config.rb    2016-03-05 12:27:32 +0900 (422df4e)
+++ test/test-config.rb    2016-03-05 12:35:07 +0900 (4058915)
@@ -1,4 +1,5 @@
 # Copyright (C) 2015-2016  Kouhei Sutou <kou �� clear-code.com>
+# Copyright (C) 2016  Masafumi Yokoyama <yokoyama �� clear-code.com>
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -28,4 +29,13 @@ class ConfigTest < Test::Unit::TestCase
       assert_nil(context.config["nonexistent"])
     end
   end
+
+  test "#delete" do
+    context.config["rroonga.key"] = "value"
+    assert_equal("value", context.config["rroonga.key"])
+    context.config.delete("rroonga.key")
+    assert do
+      not context.config["rroonga.key"]
+    end
+  end
 end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index