* [PATCH] ruby: add bindings for `notmuch_database_get_all_tags`
@ 2014-11-16 19:58 Ludovic LANGE
2014-12-31 20:11 ` David Bremner
2016-03-06 11:56 ` David Bremner
0 siblings, 2 replies; 4+ messages in thread
From: Ludovic LANGE @ 2014-11-16 19:58 UTC (permalink / raw)
To: notmuch
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!
---
NEWS | 9 +++++++++
bindings/ruby/database.c | 20 ++++++++++++++++++++
bindings/ruby/defs.h | 3 +++
bindings/ruby/init.c | 1 +
4 files changed, 33 insertions(+)
diff --git a/NEWS b/NEWS
index 44e8d05..bcd368f 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,12 @@
+Notmuch X.XX (201X-XX-XX)
+=========================
+
+Ruby Bindings
+-------------
+
+Add support for `notmuch_database_get_all_tags`
+
+
Notmuch 0.19 (2014-11-14)
=========================
diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c
index c03d701..dd36ca8 100644
--- a/bindings/ruby/database.c
+++ b/bindings/ruby/database.c
@@ -375,6 +375,26 @@ 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)
+ rb_raise (notmuch_rb_eMemoryError, "Out of memory");
+
+ 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 */
/*
--
1.8.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ruby: add bindings for `notmuch_database_get_all_tags`
2014-11-16 19:58 [PATCH] ruby: add bindings for `notmuch_database_get_all_tags` Ludovic LANGE
@ 2014-12-31 20:11 ` David Bremner
2016-03-06 11:56 ` David Bremner
1 sibling, 0 replies; 4+ messages in thread
From: David Bremner @ 2014-12-31 20:11 UTC (permalink / raw)
To: Ludovic LANGE, notmuch
Ludovic LANGE <ll-notmuchmail@lange.nom.fr> writes:
> + tags = notmuch_database_get_all_tags (db);
> + if (!tags)
> + rb_raise (notmuch_rb_eMemoryError, "Out of memory");
Hi Ludovic;
Sorry about the slow response. It's not really your fault, but this
exception is is not really correct, since there are at least two
possible error conditions which get squashed into a NULL. I have
proposed a series [1] which should make it possible to tell the
difference, but in the mean time I wonder if it would be better to
to do
rb_raise (notmuch_rb_eBaseError, "unknown notmuch error")
with a comment "XXX: figure out actual error".
Cheers,
d
[1]: id:1419788030-10567-2-git-send-email-david@tethera.net
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] ruby: add bindings for `notmuch_database_get_all_tags`
2014-11-16 19:58 [PATCH] ruby: add bindings for `notmuch_database_get_all_tags` Ludovic LANGE
2014-12-31 20:11 ` David Bremner
@ 2016-03-06 11:56 ` David Bremner
2016-05-19 11:07 ` David Bremner
1 sibling, 1 reply; 4+ messages in thread
From: David Bremner @ 2016-03-06 11:56 UTC (permalink / raw)
To: Ludovic LANGE, notmuch
From: Ludovic LANGE <ll-notmuchmail@lange.nom.fr>
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ruby: add bindings for `notmuch_database_get_all_tags`
2016-03-06 11:56 ` David Bremner
@ 2016-05-19 11:07 ` David Bremner
0 siblings, 0 replies; 4+ messages in thread
From: David Bremner @ 2016-05-19 11:07 UTC (permalink / raw)
To: Ludovic LANGE, notmuch
David Bremner <david@tethera.net> writes:
> From: Ludovic LANGE <ll-notmuchmail@lange.nom.fr>
>
> 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.
rebased version pushed to master
d
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-05-19 11:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-16 19:58 [PATCH] ruby: add bindings for `notmuch_database_get_all_tags` Ludovic LANGE
2014-12-31 20:11 ` David Bremner
2016-03-06 11:56 ` David Bremner
2016-05-19 11:07 ` David Bremner
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).