[PATCH] ruby: add all_tags method to Notmuch::Database

Peter Keen peter.keen at bugsplat.info
Mon Jul 9 07:36:48 PDT 2012


The python bindings define a binding for the all_tags method on the
database, which is pretty handy. This commit adds the same binding to
the ruby bindings.
---
 bindings/ruby/database.c |   20 ++++++++++++++++++++
 bindings/ruby/defs.h     |    3 +++
 bindings/ruby/init.c     |    1 +
 3 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c
index e84f726..d5ba108 100644
--- a/bindings/ruby/database.c
+++ b/bindings/ruby/database.c
@@ -395,3 +395,23 @@ notmuch_rb_database_query_create (VALUE self, VALUE qstrv)

     return Data_Wrap_Struct (notmuch_rb_cQuery, NULL, NULL, query);
 }
+
+/*
+ * call-seq: DB.get_all_tags() => TAGS
+ *
+ * Retrieve all tags 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)
+        rb_raise (notmuch_rb_eMemoryError, "Out of memory");
+
+    return Data_Wrap_Struct (notmuch_rb_cTags, NULL, NULL, tags);
+}
diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index fe81b3f..f1f7502 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -180,6 +180,9 @@ notmuch_rb_database_find_message_by_filename
(VALUE self, VALUE pathv);
 VALUE
 notmuch_rb_database_query_create (VALUE self, VALUE qstrv);

+VALUE
+notmuch_rb_database_get_all_tags (VALUE self);
+
 /* directory.c */
 VALUE
 notmuch_rb_directory_destroy (VALUE self);
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index f4931d3..52561c7 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -230,6 +230,7 @@ Init_notmuch (void)
     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, "query",
notmuch_rb_database_query_create, 1); /* in database.c */
+    rb_define_method (notmuch_rb_cDatabase, "all_tags",
notmuch_rb_database_get_all_tags, 0); /* in database.c */

     /*
      * Document-class: Notmuch::Directory
-- 
1.7.7.5 (Apple Git-26)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20120709/1b28f4b6/attachment.html>


More information about the notmuch mailing list