]> rtime.felk.cvut.cz Git - notmuch.git/commitdiff
ruby: add bindings for `notmuch_database_get_all_tags`
authorLudovic LANGE <ll-notmuchmail@lange.nom.fr>
Sun, 6 Mar 2016 11:56:28 +0000 (07:56 -0400)
committerDavid Bremner <david@tethera.net>
Thu, 19 May 2016 11:02:43 +0000 (08:02 -0300)
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

NEWS
bindings/ruby/database.c
bindings/ruby/defs.h
bindings/ruby/init.c
test/T395-ruby.sh

diff --git a/NEWS b/NEWS
index c945c245cb81b7b17c9d90a90f5ec1ce2d9c7d66..90e233bfa7a9a3d918c50458664350e37a2a6c9b 100644 (file)
--- 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)
 =========================
 
index c03d7011f8406931045183a02eeb0d1395eb0107..6deda5751df0d1c69fb264f17a4f04243f7dab7d 100644 (file)
@@ -374,6 +374,30 @@ notmuch_rb_database_find_message_by_filename (VALUE self, VALUE pathv)
     return Qnil;
 }
 
+/*
+ * 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
  *
index f4901a047923e3340e373b4bff8ded8335996323..167250e4a6498e64192fa0cd6ab1ebae8c52fa34 100644 (file)
@@ -177,6 +177,9 @@ notmuch_rb_database_find_message (VALUE self, VALUE idv);
 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);
 
index ab3f22df9c8106624b7e42e28bd4a805fa925686..865d6bf6b7333f6c2bd71fe0811a4c5dd907b51d 100644 (file)
@@ -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 */
 
     /*
index d5cade8fbecd7d5ddd4a5c71f1f65470861703b7..20e06917fa3f2616750910f4ea58e0fa8b51ad1a 100755 (executable)
@@ -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