Currently the simplest way to open the notmuch database properly a
client must do:

  $config = IO.popen(%w[notmuch config list]) do |io|
    io.each(chomp: true).map { |e| e.split('=') }.to_h
  end
  $db_name = config['database.path']
  $db = Notmuch::Database.new($db_name)

While this works and it's not too overly complicated, the notmuch API
already has much better constucts.

This patch series allows the user to simply do:

  $db = Notmuch::Database.open_with_config
  $config = $db.config.to_h

And much more.

Since v1 this is rebased on top of master to resolve conflicts, and a
minor style update to one test.

Felipe Contreras (3):
  ruby: add new Database.open_with_config
  ruby: add db.config
  ruby: make db.config return an enumerator

 bindings/ruby/database.c | 95 ++++++++++++++++++++++++++++++++++++++++
 bindings/ruby/defs.h     | 10 +++++
 bindings/ruby/init.c     |  2 +
 test/T395-ruby.sh        | 14 ++++++
 4 files changed, 121 insertions(+)

Range-diff against v1:
1:  0d63249e = 1:  beba4602 ruby: add new Database.open_with_config
2:  41bae8f2 ! 2:  92a36061 ruby: add db.config
    @@ Commit message
         Signed-off-by: Felipe Contreras <felipe.contre...@gmail.com>
     
      ## bindings/ruby/database.c ##
    -@@ bindings/ruby/database.c: notmuch_rb_database_query_create (VALUE self, 
VALUE qstrv)
    +@@ bindings/ruby/database.c: notmuch_rb_database_query_create (int argc, 
VALUE *argv, VALUE self)
      
          return Data_Wrap_Notmuch_Object (notmuch_rb_cQuery, 
&notmuch_rb_query_type, query);
      }
    @@ bindings/ruby/defs.h: extern ID ID_db_mode;
      extern const rb_data_type_t notmuch_rb_database_type;
     @@ bindings/ruby/defs.h: notmuch_rb_database_get_all_tags (VALUE self);
      VALUE
    - notmuch_rb_database_query_create (VALUE self, VALUE qstrv);
    + notmuch_rb_database_query_create (int argc, VALUE *argv, VALUE self);
      
     +VALUE
     +notmuch_rb_database_config (int argc, VALUE *argv, VALUE self);
    @@ bindings/ruby/init.c
     @@ bindings/ruby/init.c: Init_notmuch (void)
                      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 */
    +     rb_define_method (notmuch_rb_cDatabase, "query", 
notmuch_rb_database_query_create, -1); /* in database.c */
     +    rb_define_method (notmuch_rb_cDatabase, "config", 
notmuch_rb_database_config, -1); /* in database.c */
      
          /*
    @@ test/T395-ruby.sh: test_ruby <<EOF
     +test_begin_subtest "config"
     +notmuch config list | grep -v '^built_with\.' > EXPECTED
     +test_ruby <<"EOF"
    -+config_db = Notmuch::Database.open_with_config
    -+config_db.config { |e| puts '%s=%s' % e }
    ++Notmuch::Database.open_with_config do |db|
    ++  db.config { |e| puts '%s=%s' % e }
    ++end
     +EOF
     +
      test_done
3:  e6880180 = 3:  4efe195f ruby: make db.config return an enumerator
-- 
2.32.0
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org

Reply via email to