aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-12-13 00:21:12 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-12-13 00:21:12 +0000
commita97a2644b99eac3cb7ac8aa984c9d903b9ae70bf (patch)
tree0a35f477302c75d8e3437b1f7b9bc0e7477df071
parent2072764eff5c757f54ad6868d80bc621e461a462 (diff)
downloadpaludis-a97a2644b99eac3cb7ac8aa984c9d903b9ae70bf.tar.gz
paludis-a97a2644b99eac3cb7ac8aa984c9d903b9ae70bf.tar.xz
(ruby) Add Repository.each_metadata and Repository example.
-rw-r--r--doc/api/index.html.part2
-rw-r--r--doc/api/ruby/example_repository.rb44
-rw-r--r--ruby/repository.cc23
3 files changed, 68 insertions, 1 deletions
diff --git a/doc/api/index.html.part b/doc/api/index.html.part
index 6454975..df2af9f 100644
--- a/doc/api/index.html.part
+++ b/doc/api/index.html.part
@@ -179,7 +179,7 @@ how concepts map on to different language bindings.</p>
<tr>
<td>example_repository</td>
<td><a href="cplusplus/example__repository_8cc-example.html">C++</a></td>
- <td></td>
+ <td><a href="ruby/example_repository.html">Ruby</a></td>
<td></td>
<td>How to use Repository</td>
</tr>
diff --git a/doc/api/ruby/example_repository.rb b/doc/api/ruby/example_repository.rb
new file mode 100644
index 0000000..a0c7374
--- /dev/null
+++ b/doc/api/ruby/example_repository.rb
@@ -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
+
diff --git a/ruby/repository.cc b/ruby/repository.cc
index 63f1883..e31825f 100644
--- a/ruby/repository.cc
+++ b/ruby/repository.cc
@@ -851,6 +851,27 @@ namespace
}
}
+ /*
+ * 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 @@ namespace
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
*