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 v2 1/3] ruby: add new Database.open_with_config
Date: Tue, 29 Jun 2021 14:08:33 -0500 [thread overview]
Message-ID: <20210629190835.19381-2-felipe.contreras@gmail.com> (raw)
In-Reply-To: <20210629190835.19381-1-felipe.contreras@gmail.com>
In order to make use of notmuch_database_open_with_config.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
bindings/ruby/database.c | 62 ++++++++++++++++++++++++++++++++++++++++
bindings/ruby/defs.h | 6 ++++
bindings/ruby/init.c | 1 +
test/T395-ruby.sh | 6 ++++
4 files changed, 75 insertions(+)
diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c
index d6c804ac..89d9619e 100644
--- a/bindings/ruby/database.c
+++ b/bindings/ruby/database.c
@@ -105,6 +105,68 @@ notmuch_rb_database_open (int argc, VALUE *argv, VALUE klass)
return rb_ensure (rb_yield, obj, notmuch_rb_database_close, obj);
}
+/*
+ * call-seq: Notmuch::Database.open_with_config([database_path:, mode:, config_path:, profile:]) [{|db| ... }]
+ *
+ * Opens a database with a configuration file.
+ *
+ */
+VALUE
+notmuch_rb_database_open_with_config (int argc, VALUE *argv, VALUE klass)
+{
+ VALUE obj;
+ notmuch_database_t *db;
+ notmuch_status_t ret;
+ VALUE opts;
+ const char *database_path = NULL;
+ notmuch_database_mode_t mode = NOTMUCH_DATABASE_MODE_READ_ONLY;
+ const char *config_path = NULL;
+ const char *profile = NULL;
+
+ rb_scan_args (argc, argv, ":", &opts);
+
+ if (!NIL_P (opts)) {
+ VALUE rdatabase_path, rmode, rconfig_path, rprofile;
+ VALUE kwargs[4];
+ static ID keyword_ids[4];
+
+ if (!keyword_ids[0]) {
+ keyword_ids[0] = rb_intern_const ("database_path");
+ keyword_ids[1] = rb_intern_const ("mode");
+ keyword_ids[2] = rb_intern_const ("config_path");
+ keyword_ids[3] = rb_intern_const ("profile");
+ }
+
+ rb_get_kwargs (opts, keyword_ids, 0, 4, kwargs);
+
+ rdatabase_path = kwargs[0];
+ rmode = kwargs[1];
+ rconfig_path = kwargs[2];
+ rprofile = kwargs[3];
+
+ if (rdatabase_path != Qundef)
+ database_path = nm_str (rdatabase_path);
+ if (rmode != Qundef)
+ mode = FIX2INT (rmode);
+ if (rconfig_path != Qundef)
+ config_path = nm_str (rconfig_path);
+ if (rprofile != Qundef)
+ profile = nm_str (rprofile);
+ }
+
+ ret = notmuch_database_open_with_config (database_path, mode,
+ config_path, profile, &db,
+ NULL);
+ notmuch_rb_status_raise (ret);
+ obj = notmuch_rb_database_alloc (klass);
+ DATA_PTR (obj) = db;
+
+ if (!rb_block_given_p ())
+ return obj;
+
+ return rb_ensure (rb_yield, obj, notmuch_rb_database_close, obj);
+}
+
/*
* call-seq: DB.close => nil
*
diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index 995bcafd..cba9fd69 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -55,6 +55,9 @@ extern ID ID_db_mode;
# define RSTRING_PTR(v) (RSTRING((v))->ptr)
#endif /* !defined (RSTRING_PTR) */
+/* Simple string helpers */
+#define nm_str(str) (str != Qnil ? RSTRING_PTR (str) : NULL)
+
extern const rb_data_type_t notmuch_rb_object_type;
extern const rb_data_type_t notmuch_rb_database_type;
extern const rb_data_type_t notmuch_rb_directory_type;
@@ -134,6 +137,9 @@ notmuch_rb_database_initialize (int argc, VALUE *argv, VALUE klass);
VALUE
notmuch_rb_database_open (int argc, VALUE *argv, VALUE klass);
+VALUE
+notmuch_rb_database_open_with_config (int argc, VALUE *argv, VALUE klass);
+
VALUE
notmuch_rb_database_close (VALUE self);
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index d421c601..7b4de86a 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -259,6 +259,7 @@ Init_notmuch (void)
notmuch_rb_cDatabase = rb_define_class_under (mod, "Database", rb_cObject);
rb_define_alloc_func (notmuch_rb_cDatabase, notmuch_rb_database_alloc);
rb_define_singleton_method (notmuch_rb_cDatabase, "open", notmuch_rb_database_open, -1); /* in database.c */
+ rb_define_singleton_method (notmuch_rb_cDatabase, "open_with_config", notmuch_rb_database_open_with_config, -1); /* in database.c */
rb_define_method (notmuch_rb_cDatabase, "initialize", notmuch_rb_database_initialize, -1); /* in database.c */
rb_define_method (notmuch_rb_cDatabase, "close", notmuch_rb_database_close, 0); /* in database.c */
rb_define_method (notmuch_rb_cDatabase, "path", notmuch_rb_database_path, 0); /* in database.c */
diff --git a/test/T395-ruby.sh b/test/T395-ruby.sh
index e828efed..9a1df913 100755
--- a/test/T395-ruby.sh
+++ b/test/T395-ruby.sh
@@ -100,4 +100,10 @@ q.search_threads.each do |t|
end
EOF
+test_begin_subtest "open with config"
+echo "$MAIL_DIR" > EXPECTED
+test_ruby <<EOF
+puts Notmuch::Database.open_with_config.path
+EOF
+
test_done
--
2.32.0
next prev parent reply other threads:[~2021-06-29 19:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-29 19:08 [PATCH v2 0/3] ruby: add latest config API Felipe Contreras
2021-06-29 19:08 ` Felipe Contreras [this message]
2021-08-21 14:20 ` [PATCH v2 1/3] ruby: add new Database.open_with_config David Bremner
2021-06-29 19:08 ` [PATCH v2 2/3] ruby: add db.config Felipe Contreras
2021-06-29 19:08 ` [PATCH v2 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=20210629190835.19381-2-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).