From: Wael M. Nasreddine Date: Sat, 10 May 2014 21:40:11 +0000 (-0700) Subject: ruby: Add wrapper for notmuch_query_count_threads X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=0629afeb2668ce2f60e8efe65cdab868a1e1b257;p=notmuch.git ruby: Add wrapper for notmuch_query_count_threads --- diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h index 5b44585a..f4901a04 100644 --- a/bindings/ruby/defs.h +++ b/bindings/ruby/defs.h @@ -231,6 +231,9 @@ notmuch_rb_query_search_messages (VALUE self); VALUE notmuch_rb_query_count_messages (VALUE self); +VALUE +notmuch_rb_query_count_threads (VALUE self); + /* threads.c */ VALUE notmuch_rb_threads_destroy (VALUE self); diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c index 663271d4..ab3f22df 100644 --- a/bindings/ruby/init.c +++ b/bindings/ruby/init.c @@ -271,6 +271,7 @@ Init_notmuch (void) 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 */ + rb_define_method (notmuch_rb_cQuery, "count_threads", notmuch_rb_query_count_threads, 0); /* in query.c */ /* * Document-class: Notmuch::Threads diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c index 1658edee..a7dacba3 100644 --- a/bindings/ruby/query.c +++ b/bindings/ruby/query.c @@ -182,3 +182,22 @@ notmuch_rb_query_count_messages (VALUE self) */ return UINT2NUM(notmuch_query_count_messages(query)); } + +/* + * call-seq: QUERY.count_threads => Fixnum + * + * Return an estimate of the number of threads matching a search + */ +VALUE +notmuch_rb_query_count_threads (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 UINT2NUM(notmuch_query_count_threads(query)); +}