aboutsummaryrefslogtreecommitdiff
path: root/doc/api/ruby
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-12-12 16:06:59 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-12-12 16:06:59 +0000
commit42faf4713f0e601095164c62b9ebaf6d32461577 (patch)
tree88f4de6c8a56f15b2c479673082c5133a8aa0948 /doc/api/ruby
parenteb72c05d1ad7fd6eb98947ea1520f358f307e8fe (diff)
downloadpaludis-42faf4713f0e601095164c62b9ebaf6d32461577.tar.gz
paludis-42faf4713f0e601095164c62b9ebaf6d32461577.tar.xz
(ruby) Add missing files.
Diffstat (limited to 'doc/api/ruby')
-rw-r--r--doc/api/ruby/example_mask.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/doc/api/ruby/example_mask.rb b/doc/api/ruby/example_mask.rb
new file mode 100644
index 000000000..121305173
--- /dev/null
+++ b/doc/api/ruby/example_mask.rb
@@ -0,0 +1,58 @@
+#!/usr/bin/env ruby
+# vim: set sw=4 sts=4 et tw=100 :
+
+=begin description
+This example demonstrates how to use Mask. It displays all the
+mask keys for a particular PackageID.
+=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 package IDs for 'sys-apps/paludis'
+ids = env.package_database.query(
+ Query::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])),
+ QueryOrder::OrderByVersion)
+
+# For each ID:
+ids.each do | id |
+ puts id.to_s + ':'
+ id.masks.each do |mask|
+ puts " Key: ".ljust(31) + mask.key
+ puts " Description: ".ljust(31) + mask.description
+
+ # Some Mask subclasses contain more information than others
+ if mask.kind_of? UserMask
+ puts " Class: ".ljust(31) + 'UserMask'
+ elsif mask.kind_of? UnacceptedMask
+ puts " Class: ".ljust(31) + 'UnacceptedMask'
+ puts " Unaccepted key: ".ljust(31) + mask.unaccepted_key.raw_name unless mask.unaccepted_key.nil?
+ elsif mask.kind_of? RepositoryMask
+ puts " Class: ".ljust(31) + 'RepositoryMask'
+ puts " Mask key: ".ljust(31) + mask.mask_key.raw_name unless mask.mask_key.nil?
+ elsif mask.kind_of? UnsupportedMask
+ puts " Class: ".ljust(31) + 'UnsupportedMask'
+ puts " Explanation: ".ljust(31) + mask.explanation
+ elsif mask.kind_of? AssociationMask
+ puts " Class: ".ljust(31) + 'AssociationMask'
+ puts " Associated package: ".ljust(31) + mask.associated_package.to_s unless mask.associated_package.nil?
+ else
+ puts " Class: ".ljust(31) + 'Unknown'
+ end
+
+ puts
+
+ end
+
+ puts
+end
+
+exit exit_status
+