aboutsummaryrefslogtreecommitdiff
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
parentf7096d1f89430e7b199f2e2c26b33c8c233fb728 (diff)
downloadpaludis-ab6cb1164ad55f711aa8058c1d4d146813bfa49a.tar.gz
paludis-ab6cb1164ad55f711aa8058c1d4d146813bfa49a.tar.xz
(ruby) Add missing Query methods to Ruby. Implement example_query in Ruby.
-rw-r--r--doc/api/index.html.part2
-rw-r--r--doc/api/ruby/Makefile.am1
-rw-r--r--doc/api/ruby/example_query.rb43
-rw-r--r--ruby/query.cc2
4 files changed, 47 insertions, 1 deletions
diff --git a/doc/api/index.html.part b/doc/api/index.html.part
index 3d7ee0c..6abaff1 100644
--- a/doc/api/index.html.part
+++ b/doc/api/index.html.part
@@ -123,7 +123,7 @@ how concepts map on to different language bindings.</p>
<tr>
<td>example_query</td>
<td><a href="cplusplus/example__query_8cc-example.html">C++</a></td>
- <td></td>
+ <td><a href="ruby/example_query.html">Ruby</a></td>
<td></td>
</tr>
<tr>
diff --git a/doc/api/ruby/Makefile.am b/doc/api/ruby/Makefile.am
index 91b8cf6..ce176b3 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 0000000..e73c390
--- /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)
+
diff --git a/ruby/query.cc b/ruby/query.cc
index c6d9996..57ff82f 100644
--- a/ruby/query.cc
+++ b/ruby/query.cc
@@ -3,6 +3,7 @@
/*
* Copyright (c) 2007 Richard Brown
* Copyright (c) 2007 Alexander Færøy
+ * Copyright (c) 2007 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -259,6 +260,7 @@ namespace
rb_funcall(c_query, rb_intern("private_class_method"), 1, rb_str_new2("new"));
rb_define_method(c_query, "initialize", RUBY_FUNC_CAST(&query_init), -1);
rb_define_method(c_query, "&", RUBY_FUNC_CAST(&query_and), 1);
+ rb_define_method(c_query, "to_s", RUBY_FUNC_CAST(&Common<Query>::to_s), 0);
/*
* Document-class: Paludis::Query::Matches