aboutsummaryrefslogtreecommitdiff
path: root/doc/api/ruby
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-11-06 16:19:53 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-11-06 16:19:53 +0000
commitab6cb1164ad55f711aa8058c1d4d146813bfa49a (patch)
treeaece24455330a385d11a82f8bda83346eb2eebd9 /doc/api/ruby
parentf7096d1f89430e7b199f2e2c26b33c8c233fb728 (diff)
downloadpaludis-ab6cb1164ad55f711aa8058c1d4d146813bfa49a.tar.gz
paludis-ab6cb1164ad55f711aa8058c1d4d146813bfa49a.tar.xz
(ruby) Add missing Query methods to Ruby. Implement example_query in Ruby.
Diffstat (limited to 'doc/api/ruby')
-rw-r--r--doc/api/ruby/Makefile.am1
-rw-r--r--doc/api/ruby/example_query.rb43
2 files changed, 44 insertions, 0 deletions
diff --git a/doc/api/ruby/Makefile.am b/doc/api/ruby/Makefile.am
index 91b8cf661..ce176b32a 100644
--- a/doc/api/ruby/Makefile.am
+++ b/doc/api/ruby/Makefile.am
@@ -27,6 +27,7 @@ examples = \
example_action.rb \
example_contents.rb \
example_dep_spec.rb \
+ example_query.rb \
example_version_spec.rb
EXTRA_DIST = $(examples)
diff --git a/doc/api/ruby/example_query.rb b/doc/api/ruby/example_query.rb
new file mode 100644
index 000000000..e73c3907a
--- /dev/null
+++ b/doc/api/ruby/example_query.rb
@@ -0,0 +1,43 @@
+#!/usr/bin/env ruby
+# vim: set sw=4 sts=4 et tw=100 :
+
+require 'Paludis'
+require 'example_command_line'
+
+include Paludis
+
+# Run a query, and show its results.
+def show_query(env, query)
+ # Queries support a crude form of stringification.
+ puts "#{query}:"
+
+ # Usually the only thing clients will do with a Query object is pass it to
+ # PackageDatabase#query.
+ ids = env.package_database.query(query, QueryOrder::OrderByVersion)
+
+ # Show the results
+ ids.each do | id |
+ puts " #{id}"
+ end
+ puts
+end
+
+# We start with an Environment, respecting the user's '--environment' choice.
+env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment)
+
+# Make some queries, and display what they give.
+show_query(env, Query::Matches.new(PackageDepSpec.new("sys-apps/paludis", PackageDepSpecParseMode::Permissive)))
+
+# Queries can be combined. The resulting query is optimised internally,
+# potentially giving better performance than doing things by hand.
+show_query(env,
+ Query::Matches.new(PackageDepSpec.new("sys-apps/paludis", PackageDepSpecParseMode::Permissive)) &
+ Query::SupportsInstalledAction.new)
+
+# Usually Query::NotMasked should be combined with Query::SupportsInstallAction,
+# since installed packages aren't masked.
+show_query(env,
+ Query::Matches.new(PackageDepSpec.new("sys-apps/paludis", PackageDepSpecParseMode::Permissive)) &
+ Query::SupportsInstallAction.new &
+ Query::NotMasked.new)
+