unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: notmuch@notmuchmail.org
Cc: David Bremner <david@tethera.net>,
	Felipe Contreras <felipe.contreras@gmail.com>
Subject: [PATCH 2/3] ruby: add db.config
Date: Thu,  3 Jun 2021 22:29:00 -0500	[thread overview]
Message-ID: <20210604032901.3815539-3-felipe.contreras@gmail.com> (raw)
In-Reply-To: <20210604032901.3815539-1-felipe.contreras@gmail.com>

In order to use notmuch_config_get_pairs.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 bindings/ruby/database.c | 31 +++++++++++++++++++++++++++++++
 bindings/ruby/defs.h     |  4 ++++
 bindings/ruby/init.c     |  1 +
 test/T395-ruby.sh        |  7 +++++++
 4 files changed, 43 insertions(+)

diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c
index bc0c22cb..934cbfe8 100644
--- a/bindings/ruby/database.c
+++ b/bindings/ruby/database.c
@@ -479,3 +479,34 @@ notmuch_rb_database_query_create (VALUE self, VALUE qstrv)
 
     return Data_Wrap_Notmuch_Object (notmuch_rb_cQuery, &notmuch_rb_query_type, query);
 }
+
+/*
+ * call-seq: DB.config(prefix) {|key, value| block} => nil
+ *
+ * Calls +block+ once for each key/value pair.
+ *
+ */
+VALUE
+notmuch_rb_database_config (int argc, VALUE *argv, VALUE self)
+{
+    VALUE prefix;
+    notmuch_database_t *db;
+    notmuch_config_pairs_t *list;
+    const char *cprefix;
+
+    Data_Get_Notmuch_Database (self, db);
+
+    rb_scan_args (argc, argv, "01", &prefix);
+
+    cprefix = prefix != Qnil ? RSTRING_PTR (prefix) : "";
+
+    list = notmuch_config_get_pairs (db, cprefix);
+    for (; notmuch_config_pairs_valid (list); notmuch_config_pairs_move_to_next (list)) {
+	const char *key = notmuch_config_pairs_key (list);
+	const char *value = notmuch_config_pairs_value (list);
+	rb_yield (rb_ary_new3(2, nm_str_new (key), nm_str_new (value)));
+    }
+    notmuch_config_pairs_destroy (list);
+
+    return Qnil;
+}
diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index 78239229..f31e563b 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -57,6 +57,7 @@ extern ID ID_db_mode;
 
 /* Simple string helpers */
 #define nm_str(str) (str != Qnil ? RSTRING_PTR (str) : NULL)
+#define nm_str_new(str) (str ? rb_str_new_cstr (str) : Qnil)
 
 extern const rb_data_type_t notmuch_rb_object_type;
 extern const rb_data_type_t notmuch_rb_database_type;
@@ -182,6 +183,9 @@ notmuch_rb_database_get_all_tags (VALUE self);
 VALUE
 notmuch_rb_database_query_create (VALUE self, VALUE qstrv);
 
+VALUE
+notmuch_rb_database_config (int argc, VALUE *argv, VALUE self);
+
 /* directory.c */
 VALUE
 notmuch_rb_directory_destroy (VALUE self);
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index 27c7eba3..4b2f8655 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -277,6 +277,7 @@ Init_notmuch (void)
 		      notmuch_rb_database_find_message_by_filename, 1); /* in database.c */
     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, "config", notmuch_rb_database_config, -1); /* in database.c */
 
     /*
      * Document-class: Notmuch::Directory
diff --git a/test/T395-ruby.sh b/test/T395-ruby.sh
index 27ac4cc8..a7b09589 100755
--- a/test/T395-ruby.sh
+++ b/test/T395-ruby.sh
@@ -88,4 +88,11 @@ test_ruby <<EOF
 puts Notmuch::Database.open_with_config.path
 EOF
 
+test_begin_subtest "config"
+notmuch config list | grep -v '^built_with\.' > EXPECTED
+test_ruby <<"EOF"
+config_db = Notmuch::Database.open_with_config
+config_db.config { |e| puts '%s=%s' % e }
+EOF
+
 test_done
-- 
2.32.0.rc2

  parent reply	other threads:[~2021-06-04  3:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-04  3:28 [PATCH 0/3] ruby: add latest config API Felipe Contreras
2021-06-04  3:28 ` [PATCH 1/3] ruby: add new Database.open_with_config Felipe Contreras
2021-06-27 18:02   ` David Bremner
2021-06-27 18:17     ` Felipe Contreras
2021-06-28 14:11       ` David Bremner
2021-06-04  3:29 ` Felipe Contreras [this message]
2021-06-04  3:35   ` [PATCH 2/3] ruby: add db.config Felipe Contreras
2021-06-04  3:29 ` [PATCH 3/3] ruby: make db.config return an enumerator Felipe Contreras

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210604032901.3815539-3-felipe.contreras@gmail.com \
    --to=felipe.contreras@gmail.com \
    --cc=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).