]> git.notmuchmail.org Git - notmuch/commitdiff
ruby: Add wrapper for notmuch_query_count_messages
authorAli Polatel <alip@exherbo.org>
Mon, 7 May 2012 15:02:43 +0000 (18:02 +0300)
committerDavid Bremner <bremner@debian.org>
Tue, 8 May 2012 13:32:45 +0000 (10:32 -0300)
bindings/ruby/defs.h
bindings/ruby/init.c
bindings/ruby/query.c

index 81f652fba1d983c596b7f36557dac7d1575bc7af..25222a6cbfec7d3abc8b2d78dc8a7d00bdc04ef6 100644 (file)
@@ -222,6 +222,9 @@ notmuch_rb_query_search_threads (VALUE self);
 VALUE
 notmuch_rb_query_search_messages (VALUE self);
 
+VALUE
+notmuch_rb_query_count_messages (VALUE self);
+
 /* threads.c */
 VALUE
 notmuch_rb_threads_destroy (VALUE self);
index 4405f196413e58e0bf4a1d9fae286d6bad8d7c77..7ad0ecf37dfe5f688fb188e5d8444a15087cc842 100644 (file)
@@ -1,6 +1,6 @@
 /* The Ruby interface to the notmuch mail library
  *
- * Copyright © 2010, 2011 Ali Polatel
+ * Copyright © 2010, 2011, 2012 Ali Polatel
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -236,6 +236,7 @@ Init_notmuch (void)
     rb_define_method (notmuch_rb_cQuery, "to_s", notmuch_rb_query_get_string, 0); /* in query.c */
     rb_define_method (notmuch_rb_cQuery, "search_threads", notmuch_rb_query_search_threads, 0); /* in query.c */
     rb_define_method (notmuch_rb_cQuery, "search_messages", notmuch_rb_query_search_messages, 0); /* in query.c */
+    rb_define_method (notmuch_rb_cQuery, "count_messages", notmuch_rb_query_count_messages, 0); /* in query.c */
 
     /*
      * Document-class: Notmuch::Threads
index 74fd58586dc34232fe26b3064d98fc787c42004b..02b7819eb6856e12aa25975dde9d506a15be8d01 100644 (file)
@@ -1,6 +1,6 @@
 /* The Ruby interface to the notmuch mail library
  *
- * Copyright © 2010, 2011 Ali Polatel
+ * Copyright © 2010, 2011, 2012 Ali Polatel
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -127,3 +127,22 @@ notmuch_rb_query_search_messages (VALUE self)
 
     return Data_Wrap_Struct (notmuch_rb_cMessages, NULL, NULL, messages);
 }
+
+/*
+ * call-seq: QUERY.count_messages => Fixnum
+ *
+ * Return an estimate of the number of messages matching a search
+ */
+VALUE
+notmuch_rb_query_count_messages (VALUE self)
+{
+    notmuch_query_t *query;
+
+    Data_Get_Notmuch_Query (self, query);
+
+    /* Xapian exceptions are not handled properly.
+     * (function may return 0 after printing a message)
+     * Thus there is nothing we can do here...
+     */
+    return UINT2FIX(notmuch_query_count_messages(query));
+}