aboutsummaryrefslogtreecommitdiff
path: root/doc/api/ruby/example_repository.rb
diff options
context:
space:
mode:
Diffstat (limited to 'doc/api/ruby/example_repository.rb')
-rw-r--r--doc/api/ruby/example_repository.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/doc/api/ruby/example_repository.rb b/doc/api/ruby/example_repository.rb
new file mode 100644
index 000000000..a0c7374d1
--- /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
+