aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-12-15 23:18:21 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-12-15 23:18:21 +0000
commit8371766fa48f3214d25f374c37e58f92f31a6431 (patch)
tree5e93e50aae4b59f118fe1c909eeb9a329a50171b /doc
parentf9f3e2fbb9b312fa72a708b2aaf1a3eb5ab05bce (diff)
downloadpaludis-8371766fa48f3214d25f374c37e58f92f31a6431.tar.gz
paludis-8371766fa48f3214d25f374c37e58f92f31a6431.tar.xz
(ruby) Add example_package_database.rb, AmbiguousPackageNameError.options.
Diffstat (limited to 'doc')
-rw-r--r--doc/api/index.html.part2
-rw-r--r--doc/api/ruby/example_package_database.rb42
2 files changed, 43 insertions, 1 deletions
diff --git a/doc/api/index.html.part b/doc/api/index.html.part
index df2af9f77..8659124af 100644
--- a/doc/api/index.html.part
+++ b/doc/api/index.html.part
@@ -151,7 +151,7 @@ how concepts map on to different language bindings.</p>
<tr>
<td>example_package_database</td>
<td><a href="cplusplus/example__package__database_8cc-example.html">C++</a></td>
- <td></td>
+ <td><a href="ruby/example_package_database.html">Ruby</a></td>
<td></td>
<td>How to use PackageDatabase</td>
</tr>
diff --git a/doc/api/ruby/example_package_database.rb b/doc/api/ruby/example_package_database.rb
new file mode 100644
index 000000000..913d20277
--- /dev/null
+++ b/doc/api/ruby/example_package_database.rb
@@ -0,0 +1,42 @@
+#!/usr/bin/env ruby
+# vim: set sw=4 sts=4 et tw=100 :
+
+=begin description
+This example demonstrates how to use Mask. It displays all the
+mask keys for a particular PackageID.
+=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)
+
+# The most useful PackageDatabase method is PackageDatabase::query,
+# which is covered in other examples. But there are others:
+if env.package_database.has_repository_named?('gentoo')
+ repo = env.package_database.fetch_repository('gentoo')
+ puts "Repository 'gentoo' exists, and has format '" +
+ (repo.format_key ? repo.format_key.value : '') + "'"
+end
+
+puts "Our favourite repository is '#{env.package_database.favourite_repository}'"
+
+begin
+ name = env.package_database.fetch_unique_qualified_package_name('git')
+ puts "The only package named 'git' is '#{name}'"
+rescue NoSuchPackageError
+ puts "There is no package named 'git'"
+rescue AmbiguousPackageNameError
+ puts "There are several packages named 'git':"
+ $!.options.each do |o|
+ puts " #{o}"
+ end
+end
+
+exit exit_status
+