aboutsummaryrefslogtreecommitdiffhomepage
path: root/bindings/ruby
diff options
context:
space:
mode:
authorGravatar Ali Polatel <alip@exherbo.org>2012-05-07 18:02:43 +0300
committerGravatar David Bremner <bremner@debian.org>2012-05-08 10:32:45 -0300
commitd0000daab3f2b04b6b39210dd219de26fa2c8c13 (patch)
treed99f674bc33b8c1c6c1827a010334337aeb0552a /bindings/ruby
parent4997ec95719a50a1882ec9b84dcb31e7984a3565 (diff)
ruby: Add wrapper for notmuch_query_count_messages
Diffstat (limited to 'bindings/ruby')
-rw-r--r--bindings/ruby/defs.h3
-rw-r--r--bindings/ruby/init.c3
-rw-r--r--bindings/ruby/query.c21
3 files changed, 25 insertions, 2 deletions
diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index 81f652fb..25222a6c 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -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);
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index 4405f196..7ad0ecf3 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -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
diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c
index 74fd5858..02b7819e 100644
--- a/bindings/ruby/query.c
+++ b/bindings/ruby/query.c
@@ -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));
+}