aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-11-06 12:39:18 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-11-06 12:39:18 +0000
commitace8e9eb6ef9c7cc552d9dc3bab5b9f7296523db (patch)
tree1a9f095628cc3422afed3bd9d1dd67b8b7aa14a1
parent61c8bcc3acc217ffcf296e229512bdd362b80093 (diff)
downloadpaludis-ace8e9eb6ef9c7cc552d9dc3bab5b9f7296523db.tar.gz
paludis-ace8e9eb6ef9c7cc552d9dc3bab5b9f7296523db.tar.xz
More Ruby examples
-rw-r--r--doc/api/index.html.part4
-rw-r--r--doc/api/ruby/Makefile.am3
-rw-r--r--doc/api/ruby/example_contents.rb60
3 files changed, 64 insertions, 3 deletions
diff --git a/doc/api/index.html.part b/doc/api/index.html.part
index 6fddf49..945ad19 100644
--- a/doc/api/index.html.part
+++ b/doc/api/index.html.part
@@ -33,13 +33,13 @@ how concepts map on to different language bindings.</p>
<tr>
<td>example_action</td>
<td><a href="cplusplus/example__action_8cc-example.html">C++</a></td>
- <td></td>
+ <td><a href="ruby/example_action.html">Ruby</a></td>
<td></td>
</tr>
<tr>
<td>example_contents</td>
<td><a href="cplusplus/example__contents_8cc-example.html">C++</a></td>
- <td></td>
+ <td><a href="ruby/example_contents.html">Ruby</a></td>
<td></td>
</tr>
<tr>
diff --git a/doc/api/ruby/Makefile.am b/doc/api/ruby/Makefile.am
index cfc0936..3a70e28 100644
--- a/doc/api/ruby/Makefile.am
+++ b/doc/api/ruby/Makefile.am
@@ -24,7 +24,8 @@ dist_noinst_SCRIPTS = create_ruby_doc.rb
examples = \
example_command_line.rb \
example_about.rb \
- example_action.rb
+ example_action.rb \
+ example_contents.rb
EXTRA_DIST = $(examples)
diff --git a/doc/api/ruby/example_contents.rb b/doc/api/ruby/example_contents.rb
new file mode 100644
index 0000000..7fba374
--- /dev/null
+++ b/doc/api/ruby/example_contents.rb
@@ -0,0 +1,60 @@
+#!/usr/bin/env ruby
+# vim: set sw=4 sts=4 et tw=100 :
+
+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 package IDs for isntalled 'sys-apps/paludis'
+ids = env.package_database.query(
+ Query::Matches.new(PackageDepSpec.new("sys-apps/paludis", PackageDepSpecParseMode::Permissive)) &
+ Query::SupportsInstalledAction.new,
+ QueryOrder::OrderByVersion)
+
+# For each ID:
+ids.each do | id |
+ # Do we have a contents key? PackageID _key methods can return Nil.
+ if not id.contents_key
+ puts "ID '#{id}' does not provide a contents key."
+ else
+ puts "ID '#{id}' provides contents key:"
+
+ # Contents is made up of a collection of ContentsEntry instances.
+ id.contents_key.value.each do | c |
+
+ # Some ContentsEntry subclasses contain more information than others
+ if c.kind_of? ContentsDevEntry
+ puts "device #{c.name}"
+
+ elsif c.kind_of? ContentsMiscEntry
+ puts "misc #{c.name}"
+
+ elsif c.kind_of? ContentsFileEntry
+ puts "file #{c.name}"
+
+ elsif c.kind_of? ContentsDirEntry
+ puts "dir #{c.name}"
+
+ elsif c.kind_of? ContentsFifoEntry
+ puts "fifo #{c.name}"
+
+ elsif c.kind_of? ContentsSymEntry
+ puts "sym #{c.name} -> #{c.target}"
+
+ else
+ puts "unknown #{c}"
+ end
+ end
+
+ puts
+ end
+end
+
+exit exit_status
+