From: David Bremner Date: Sun, 6 Mar 2016 11:56:28 +0000 (+2000) Subject: [PATCH] ruby: add bindings for `notmuch_database_get_all_tags` X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e7951e8294f8d3adf5379ffc122e4fc15cbc6409;p=notmuch-archives.git [PATCH] ruby: add bindings for `notmuch_database_get_all_tags` --- diff --git a/6d/00ccdc88b6846a0254f6a765b4c7eac160dbda b/6d/00ccdc88b6846a0254f6a765b4c7eac160dbda new file mode 100644 index 000000000..e05856b96 --- /dev/null +++ b/6d/00ccdc88b6846a0254f6a765b4c7eac160dbda @@ -0,0 +1,182 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 3BBD76DE1348 + for ; Sun, 6 Mar 2016 03:56:43 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: -0.034 +X-Spam-Level: +X-Spam-Status: No, score=-0.034 tagged_above=-999 required=5 + tests=[AWL=-0.023, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] + autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id zT9V4IXtKhI3 for ; + Sun, 6 Mar 2016 03:56:40 -0800 (PST) +Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) + by arlo.cworth.org (Postfix) with ESMTPS id AE3156DE021D + for ; Sun, 6 Mar 2016 03:56:40 -0800 (PST) +Received: from remotemail by fethera.tethera.net with local (Exim 4.84) + (envelope-from ) + id 1acXJD-0000tn-BY; Sun, 06 Mar 2016 06:57:15 -0500 +Received: (nullmailer pid 3486 invoked by uid 1000); + Sun, 06 Mar 2016 11:56:35 -0000 +From: David Bremner +To: Ludovic LANGE , notmuch@notmuchmail.org +Subject: [PATCH] ruby: add bindings for `notmuch_database_get_all_tags` +Date: Sun, 6 Mar 2016 07:56:28 -0400 +Message-Id: <1457265388-3434-1-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.7.0 +In-Reply-To: <1416167892-15686-1-git-send-email-ll-notmuchmail@lange.nom.fr> +References: <1416167892-15686-1-git-send-email-ll-notmuchmail@lange.nom.fr> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.20 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sun, 06 Mar 2016 11:56:43 -0000 + +From: Ludovic LANGE + +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 +--- + +I'm not super happy with the "%s", but apparently the compiler is not smart enough to accept just "msg" there. + + NEWS | 5 +++++ + bindings/ruby/database.c | 24 ++++++++++++++++++++++++ + bindings/ruby/defs.h | 3 +++ + bindings/ruby/init.c | 1 + + test/T395-ruby.sh | 16 ++++++++++++++++ + 5 files changed, 49 insertions(+) + +diff --git a/NEWS b/NEWS +index 613fdfe..43dc5e0 100644 +--- a/NEWS ++++ b/NEWS +@@ -1,6 +1,11 @@ + Notmuch 0.22 (UNRELEASED) + ========================= + ++Ruby Bindings ++------------- ++ ++Add support for `notmuch_database_get_all_tags` ++ + Emacs Interface + --------------- + +diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c +index c03d701..6deda57 100644 +--- a/bindings/ruby/database.c ++++ b/bindings/ruby/database.c +@@ -375,6 +375,30 @@ notmuch_rb_database_find_message_by_filename (VALUE self, VALUE pathv) + } + + /* ++ * 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 + * + * Retrieve a query object for the query string 'query' +diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h +index f4901a0..167250e 100644 +--- a/bindings/ruby/defs.h ++++ b/bindings/ruby/defs.h +@@ -178,6 +178,9 @@ 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); + + /* directory.c */ +diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c +index ab3f22d..865d6bf 100644 +--- a/bindings/ruby/init.c ++++ b/bindings/ruby/init.c +@@ -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 */ + + /* +diff --git a/test/T395-ruby.sh b/test/T395-ruby.sh +index d5cade8..20e0691 100755 +--- a/test/T395-ruby.sh ++++ b/test/T395-ruby.sh +@@ -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 +-- +2.7.0 +