In order to make use of notmuch_database_open_with_config.
Signed-off-by: Felipe Contreras <[email protected]>
---
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 bb993d86..bc0c22cb 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 9860ee17..78239229 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 bedfbf60..27c7eba3 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 d36d4aff..27ac4cc8 100755
--- a/test/T395-ruby.sh
+++ b/test/T395-ruby.sh
@@ -82,4 +82,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.rc2
_______________________________________________
notmuch mailing list -- [email protected]
To unsubscribe send an email to [email protected]