aboutsummaryrefslogtreecommitdiff
path: root/doc/api
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2008-01-18 23:48:33 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2008-01-18 23:48:33 +0000
commit31d62bdfa5664f56557164ce9f78174ea10a61db (patch)
treed8c0b499b805e47824f3e8005586dfbe91df8e5f /doc/api
parent6bb6418a5c51cbdf7a12e06204a864acbac03dbf (diff)
downloadpaludis-31d62bdfa5664f56557164ce9f78174ea10a61db.tar.gz
paludis-31d62bdfa5664f56557164ce9f78174ea10a61db.tar.xz
(ruby) Add match_package_in_set and example_match_package.
Diffstat (limited to 'doc/api')
-rw-r--r--doc/api/index.html.part2
-rw-r--r--doc/api/ruby/Makefile.am1
-rw-r--r--doc/api/ruby/example_match_package.rb42
3 files changed, 44 insertions, 1 deletions
diff --git a/doc/api/index.html.part b/doc/api/index.html.part
index 8659124af..e903ebc12 100644
--- a/doc/api/index.html.part
+++ b/doc/api/index.html.part
@@ -130,7 +130,7 @@ how concepts map on to different language bindings.</p>
<tr>
<td>example_match_package</td>
<td><a href="cplusplus/example__match__package_8cc-example.html">C++</a></td>
- <td></td>
+ <td><a href="ruby/example_match_package.html">Ruby</a></td>
<td></td>
<td>How to use paludis::match_package and paludis::match_package_in_set</td>
</tr>
diff --git a/doc/api/ruby/Makefile.am b/doc/api/ruby/Makefile.am
index 12be42547..3562baa38 100644
--- a/doc/api/ruby/Makefile.am
+++ b/doc/api/ruby/Makefile.am
@@ -31,6 +31,7 @@ examples = \
example_dep_spec.rb \
example_dep_tree.rb \
example_mask.rb \
+ example_match_package.rb \
example_query.rb \
example_version_operator.rb \
example_version_spec.rb
diff --git a/doc/api/ruby/example_match_package.rb b/doc/api/ruby/example_match_package.rb
new file mode 100644
index 000000000..0c0d3592c
--- /dev/null
+++ b/doc/api/ruby/example_match_package.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 contents. It displays details about
+the files installed by 'sys-apps/paludis'.
+=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)
+
+# Fetch all installed packages
+ids = env.package_database.query(Query::SupportsInstalledAction.new, QueryOrder::OrderByVersion);
+
+# Fetch the 'system' and 'world' sets. Ordinarily we should check for
+# Nil here, but these two sets will always exist.
+system = env.set('system')
+world = env.set('world')
+
+# For each ID:
+ids.each do | id |
+ # Is it paludis?
+ if match_package(env, parse_user_package_dep_spec('sys-apps/paludis', []), id)
+ puts id.to_s.ljust(49) + ': paludis'
+ elsif match_package_in_set(env, system, id)
+ puts id.to_s.ljust(49) + ': system'
+ elsif match_package_in_set(env, world, id)
+ puts id.to_s.ljust(49) + ': world'
+ else
+ puts id.to_s.ljust(49) + ': nothing'
+ end
+end
+
+exit exit_status
+