Signed-off-by: Felipe Contreras <[email protected]>
---
bindings/ruby/database.c | 45 ++++++++++++++++++++++++++++++++++++++++
bindings/ruby/defs.h | 6 ++++++
bindings/ruby/init.c | 2 ++
3 files changed, 53 insertions(+)
diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c
index 4372afa1..10bdab4e 100644
--- a/bindings/ruby/database.c
+++ b/bindings/ruby/database.c
@@ -497,3 +497,48 @@ notmuch_rb_database_revision (VALUE self)
rev = notmuch_database_get_revision (db, &uuid);
return rb_ary_new3(2, INT2FIX (rev), rb_str_new2 (uuid));
}
+
+/*
+ * call-seq: DB.set_config(key, value) => nil
+ *
+ * Sets configuration key to value.
+ */
+VALUE
+notmuch_rb_database_set_config (VALUE self, VALUE key, VALUE value)
+{
+ notmuch_database_t *db;
+ notmuch_status_t ret;
+ const char *cvalue;
+
+ Data_Get_Notmuch_Database (self, db);
+
+ cvalue = value != Qnil ? RSTRING_PTR (value) : "";
+ ret = notmuch_database_set_config (db, RSTRING_PTR (key), cvalue);
+ notmuch_rb_status_raise (ret);
+
+ return Qnil;
+}
+
+/*
+ * call-seq: DB.get_config(key) => String
+ *
+ * Retrieves a configuration key.
+ */
+VALUE
+notmuch_rb_database_get_config (VALUE self, VALUE key)
+{
+ notmuch_database_t *db;
+ notmuch_status_t ret;
+ char *value;
+ VALUE rvalue;
+
+ Data_Get_Notmuch_Database (self, db);
+
+ ret = notmuch_database_get_config (db, RSTRING_PTR (key), &value);
+ notmuch_rb_status_raise (ret);
+
+ rvalue = rb_str_new2 (value);
+ free (value);
+
+ return rvalue;
+}
diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index 3ef228b7..352458c8 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -211,6 +211,12 @@ notmuch_rb_database_query_create (int argc, VALUE *argv,
VALUE self);
VALUE
notmuch_rb_database_revision (VALUE self);
+VALUE
+notmuch_rb_database_set_config (VALUE self, VALUE key, VALUE value);
+
+VALUE
+notmuch_rb_database_get_config (VALUE self, VALUE key);
+
/* directory.c */
VALUE
notmuch_rb_directory_destroy (VALUE self);
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index 625c6c4d..95dc237f 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -284,6 +284,8 @@ Init_notmuch (void)
rb_define_method (notmuch_rb_cDatabase, "all_tags",
notmuch_rb_database_get_all_tags, 0); /* in database.c */
rb_define_method (notmuch_rb_cDatabase, "query",
notmuch_rb_database_query_create, -1); /* in database.c */
rb_define_method (notmuch_rb_cDatabase, "revision",
notmuch_rb_database_revision, 0); /* in database.c */
+ rb_define_method (notmuch_rb_cDatabase, "set_config",
notmuch_rb_database_set_config, 2); /* in database.c */
+ rb_define_method (notmuch_rb_cDatabase, "get_config",
notmuch_rb_database_get_config, 1); /* in database.c */
/*
* Document-class: Notmuch::Directory
--
2.40.0
_______________________________________________
notmuch mailing list -- [email protected]
To unsubscribe send an email to [email protected]