aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic LANGE <ll-notmuchmail@lange.nom.fr>2016-03-06 07:56:28 -0400
committerDavid Bremner <david@tethera.net>2016-05-19 08:02:43 -0300
commit7e6e23c36e290d4b22b0449766a6ef2107f1ef6c (patch)
tree84bfc83815e67c8469689c0bea30df2cbb37ad98
parentb183f2635eaf323066f26c7ca22d931d4f4ccd3a (diff)
ruby: add bindings for `notmuch_database_get_all_tags`
The Ruby bindings were missing a way to get all the tags of the database. Now you should be able to access this with the public instance method `all_tags` of your database object. Example of use: notmuchdb = Notmuch::Database.new path, { :create => false, :mode => Notmuch::MODE_READ_ONLY } my_tags = notmuchdb.all_tags my_tags.each { |tag| print tag } my_tags.destroy! Amended by db: improve error reporting, add test
-rw-r--r--NEWS8
-rw-r--r--bindings/ruby/database.c24
-rw-r--r--bindings/ruby/defs.h3
-rw-r--r--bindings/ruby/init.c1
-rwxr-xr-xtest/T395-ruby.sh16
5 files changed, 52 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index c945c245..90e233bf 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,11 @@
+Notmuch 0.23 (UNRELEASED)
+=========================
+
+Ruby Bindings
+-------------
+
+Add support for `notmuch_database_get_all_tags`
+
Notmuch 0.22 (2016-04-26)
=========================
diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c
index c03d7011..6deda575 100644
--- a/bindings/ruby/database.c
+++ b/bindings/ruby/database.c
@@ -375,6 +375,30 @@ notmuch_rb_database_find_message_by_filename (VALUE self, VALUE pathv)
}
/*
+ * call-seq: DB.get_all_tags() => TAGS
+ *
+ * Returns a list of all tags found in the database.
+ */
+VALUE
+notmuch_rb_database_get_all_tags (VALUE self)
+{
+ notmuch_database_t *db;
+ notmuch_tags_t *tags;
+
+ Data_Get_Notmuch_Database (self, db);
+
+ tags = notmuch_database_get_all_tags (db);
+ if (!tags) {
+ const char *msg = notmuch_database_status_string (db);
+ if (!msg)
+ msg = "Unknown notmuch error";
+
+ rb_raise (notmuch_rb_eBaseError, "%s", msg);
+ }
+ return Data_Wrap_Struct (notmuch_rb_cTags, NULL, NULL, tags);
+}
+
+/*
* call-seq: DB.query(query) => QUERY
*
* Retrieve a query object for the query string 'query'
diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index f4901a04..167250e4 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -178,6 +178,9 @@ VALUE
notmuch_rb_database_find_message_by_filename (VALUE self, VALUE pathv);
VALUE
+notmuch_rb_database_get_all_tags (VALUE self);
+
+VALUE
notmuch_rb_database_query_create (VALUE self, VALUE qstrv);
/* directory.c */
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index ab3f22df..865d6bf6 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -229,6 +229,7 @@ Init_notmuch (void)
notmuch_rb_database_find_message, 1); /* in database.c */
rb_define_method (notmuch_rb_cDatabase, "find_message_by_filename",
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 */
/*
diff --git a/test/T395-ruby.sh b/test/T395-ruby.sh
index d5cade8f..20e06917 100755
--- a/test/T395-ruby.sh
+++ b/test/T395-ruby.sh
@@ -83,4 +83,20 @@ EOF
notmuch count --output=threads tag:inbox > EXPECTED
test_expect_equal_file OUTPUT EXPECTED
+test_begin_subtest "get all tags"
+test_ruby <<"EOF"
+require 'notmuch'
+$maildir = ENV['MAIL_DIR']
+if not $maildir then
+ abort('environment variable MAIL_DIR must be set')
+end
+@db = Notmuch::Database.new($maildir)
+@t = @db.all_tags()
+for tag in @t do
+ print tag,"\n"
+end
+EOF
+notmuch search --output=tags '*' > EXPECTED
+test_expect_equal_file OUTPUT EXPECTED
+
test_done