[paludis-commits] r4071 - in trunk: . doc/api doc/api/ruby ruby

rbrown at svn.pioto.org rbrown at svn.pioto.org
Thu Dec 13 00:21:13 UTC 2007


Author: rbrown
Date: 2007-12-13 00:21:12 +0000 (Thu, 13 Dec 2007)
New Revision: 4071

Added:
   trunk/doc/api/ruby/example_repository.rb
Modified:
   trunk/ChangeLog
   trunk/doc/api/index.html.part
   trunk/ruby/repository.cc
Log:
(ruby) Add Repository.each_metadata and Repository example.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-12-12 23:45:53 UTC (rev 4070)
+++ trunk/ChangeLog	2007-12-13 00:21:12 UTC (rev 4071)
@@ -7,6 +7,11 @@
 
 2007-12-12 Richard Brown
 
+	* doc/api/, doc/api/ruby/, ruby/: (ruby) Add Repository.each_metadata
+	and Repository example.
+
+2007-12-12 Richard Brown
+
 	* doc/api/ruby/, ruby/: (ruby) Add PackageID example.
 
 2007-12-12 Richard Brown

Modified: trunk/doc/api/index.html.part
===================================================================
--- trunk/doc/api/index.html.part	2007-12-12 23:45:53 UTC (rev 4070)
+++ trunk/doc/api/index.html.part	2007-12-13 00:21:12 UTC (rev 4071)
@@ -179,8 +179,8 @@
     <tr>
         <td>example_repository</td>
         <td><a href="cplusplus/example__repository_8cc-example.html">C++</a></td>
+        <td><a href="ruby/example_repository.html">Ruby</a></td>
         <td></td>
-        <td></td>
         <td>How to use Repository</td>
     </tr>
     <tr>

Added: trunk/doc/api/ruby/example_repository.rb
===================================================================
--- trunk/doc/api/ruby/example_repository.rb	                        (rev 0)
+++ trunk/doc/api/ruby/example_repository.rb	2007-12-13 00:21:12 UTC (rev 4071)
@@ -0,0 +1,44 @@
+#!/usr/bin/env ruby
+# vim: set sw=4 sts=4 et tw=100 :
+
+=begin description
+This example demonstrates how to use Repository.
+=end
+
+require 'Paludis'
+require 'example_command_line'
+
+include Paludis
+
+exit_status = 0
+
+# We start with an Environment, respecting the user's '--environment' choice.
+env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment)
+
+# For each repository
+env.package_database.repositories do |repo|
+    # A repository is identified by its name.
+    puts repo.name + ':'
+
+    # Like a PackageID, a Repository has metadata. Usually metadata
+    # keys will be available for all of the configuration options for
+    # that repository; some repositories also provide more (ebuild
+    # format repositories, for example, provide info_pkgs too). See
+    # "example_metadata_key.rb" for how to display a metadata key 
+    # in detail.
+    puts "    Metadata Keys:".ljust(30)
+    repo.each_metadata do |key|
+        puts "        #{key.human_name}"
+    end
+
+    # Repositories support various methods for querying categories,
+    # packages, IDs and so on. These methods are used by
+    # PackageDatabase::query, but are also sometimes of direct use to
+    # clients.
+    puts "    Number of categories: ".ljust(31) + repo.category_names.length.to_s
+    puts "    IDs for sys-apps/paludis: ".ljust(31) + repo.package_ids('sys-apps/paludis').join(' ')
+
+end
+
+exit exit_status
+

Modified: trunk/ruby/repository.cc
===================================================================
--- trunk/ruby/repository.cc	2007-12-12 23:45:53 UTC (rev 4070)
+++ trunk/ruby/repository.cc	2007-12-13 00:21:12 UTC (rev 4071)
@@ -851,6 +851,27 @@
         }
     }
 
+    /*
+     * call-seq:
+     *     each_metadata {|key| block } -> Nil
+     *
+     * Our metadata.
+     */
+    VALUE
+    repository_each_metadata(VALUE self)
+    {
+        tr1::shared_ptr<Repository> * self_ptr;
+        Data_Get_Struct(self, tr1::shared_ptr<Repository>, self_ptr);
+        for (Repository::MetadataConstIterator it((*self_ptr)->begin_metadata()),
+                it_end((*self_ptr)->end_metadata()); it_end != it; ++it)
+        {
+            VALUE val(metadata_key_to_value(*it));
+            if (Qnil != val)
+                rb_yield(val);
+        }
+            return Qnil;
+    }
+
     void do_register_repository()
     {
         /*
@@ -907,6 +928,8 @@
 
         rb_define_method(c_repository, "check_qa", RUBY_FUNC_CAST(&repository_check_qa),5);
 
+        rb_define_method(c_repository, "each_metadata", RUBY_FUNC_CAST(&repository_each_metadata), 0);
+
         /*
          * Document-class: Paludis::ProfilesDescLine
          *



More information about the paludis-commits mailing list