aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-11-18 16:49:01 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-11-18 16:49:01 +0000
commit902d089ea4bcf9658e282fd7427462d8e821bb99 (patch)
tree41d9c1b45e858d4b6ffa82e9152c9d96a13278c6
parent010d69a2e15df34fb7a75a6f20ee20eab6ab2628 (diff)
downloadpaludis-902d089ea4bcf9658e282fd7427462d8e821bb99.tar.gz
paludis-902d089ea4bcf9658e282fd7427462d8e821bb99.tar.xz
(ruby) Add example_environment.
-rw-r--r--doc/api/index.html.part2
-rw-r--r--doc/api/ruby/Makefile.am1
-rw-r--r--doc/api/ruby/example_environment.rb53
3 files changed, 55 insertions, 1 deletions
diff --git a/doc/api/index.html.part b/doc/api/index.html.part
index 2089186..f93ea83 100644
--- a/doc/api/index.html.part
+++ b/doc/api/index.html.part
@@ -109,7 +109,7 @@ how concepts map on to different language bindings.</p>
<tr>
<td>example_environment</td>
<td><a href="cplusplus/example__environment_8cc-example.html">C++</a></td>
- <td></td>
+ <td><a href="ruby/example_environment.html">Ruby</a></td>
<td></td>
<td>How to use EnvironmentMaker and the resultant Environment</td>
</tr>
diff --git a/doc/api/ruby/Makefile.am b/doc/api/ruby/Makefile.am
index ceab0be..f655121 100644
--- a/doc/api/ruby/Makefile.am
+++ b/doc/api/ruby/Makefile.am
@@ -27,6 +27,7 @@ examples = \
example_about.rb \
example_action.rb \
example_contents.rb \
+ example_environment.rb \
example_dep_spec.rb \
example_dep_tree.rb \
example_query.rb \
diff --git a/doc/api/ruby/example_environment.rb b/doc/api/ruby/example_environment.rb
new file mode 100644
index 0000000..6732162
--- /dev/null
+++ b/doc/api/ruby/example_environment.rb
@@ -0,0 +1,53 @@
+#!/usr/bin/env ruby
+# vim: set sw=4 sts=4 et tw=80 :
+
+=begin description
+This example demonstrates how to use EnvironmentMaker and the resultant
+Environment.
+=end
+
+require 'Paludis'
+require 'example_command_line'
+
+include Paludis
+
+exit_status = 0
+
+# We use EnvironmentMaker to construct an environment from the user's
+# --environment commandline choice. With an empty string, this uses the
+# distribution-defined default environment. With a non-empty string, it
+# is split into two parts upon the first colon (if there is no colon,
+# the second part is considered empty). The first part is the name of
+# the environment class to use (e.g. 'paludis', 'portage') and the
+# second part is passed as parameters to be handled by that
+# environment's constructor.
+env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment)
+
+# A lot of the Environment members aren't very useful to clients. The
+# mask related methods are used by PackageID, and shouldn't usually be
+# called directly from clients. The system information and mirror
+# functions are mostly for use by Repository subclasses. That leaves
+# the package database, sets and (currently, although this may well
+# change in the future) use flag queries. The package database has its
+# own examples, so we'll start with sets:
+
+world = env.set('world')
+if (world)
+
+ # see examples_dep_tree.rb for how to make use of this set
+ puts "World set exists"
+else
+ puts "No world set defined"
+end
+
+# And use flags, for which we need package IDs:
+ids = env.package_database.query(
+ Query::Matches.new(PackageDepSpec.new('sys-apps/paludis', PackageDepSpecParseMode::Permissive)) &
+ Query::SupportsInstalledAction.new,
+ QueryOrder::OrderByVersion)
+
+if (ids.length > 0)
+ id = ids.last
+ print "Use flag 'ruby' for ID '#{id.to_s}' is "
+ puts env.query_use('ruby', id) ? 'enabled' : 'disabled'
+end