aboutsummaryrefslogtreecommitdiff
path: root/doc/api/ruby/example_match_package.rb
diff options
context:
space:
mode:
Diffstat (limited to 'doc/api/ruby/example_match_package.rb')
-rw-r--r--doc/api/ruby/example_match_package.rb42
1 files changed, 42 insertions, 0 deletions
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
+