aboutsummaryrefslogtreecommitdiff
path: root/doc/api/ruby
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-06-01 13:51:46 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-06-01 13:51:46 +0000
commit87294dc0c47918934ac032e9a080e8cf386f9bf2 (patch)
tree36dc289aa22200601ec28f2d7b497cd078e34ab6 /doc/api/ruby
parent3b9f4ed10c9eb6901f33c7037989f3b67eb5de07 (diff)
downloadpaludis-87294dc0c47918934ac032e9a080e8cf386f9bf2.tar.gz
paludis-87294dc0c47918934ac032e9a080e8cf386f9bf2.tar.xz
New Selection + Filter + Generator interface using Environment, replacing the old PackageDatabase Query. Fixes: ticket:559
Diffstat (limited to 'doc/api/ruby')
-rw-r--r--doc/api/ruby/Makefile.am2
-rw-r--r--doc/api/ruby/example_action.rb5
-rw-r--r--doc/api/ruby/example_contents.rb7
-rw-r--r--doc/api/ruby/example_dep_spec.rb101
-rw-r--r--doc/api/ruby/example_dep_tree.rb4
-rw-r--r--doc/api/ruby/example_environment.rb23
-rw-r--r--doc/api/ruby/example_mask.rb5
-rw-r--r--doc/api/ruby/example_match_package.rb3
-rw-r--r--doc/api/ruby/example_package_database.rb3
-rw-r--r--doc/api/ruby/example_package_id.rb9
-rw-r--r--doc/api/ruby/example_query.rb47
11 files changed, 25 insertions, 184 deletions
diff --git a/doc/api/ruby/Makefile.am b/doc/api/ruby/Makefile.am
index da1a920f9..37250d131 100644
--- a/doc/api/ruby/Makefile.am
+++ b/doc/api/ruby/Makefile.am
@@ -27,14 +27,12 @@ examples = \
example_action.rb \
example_command_line.rb \
example_contents.rb \
- example_dep_spec.rb \
example_dep_tree.rb \
example_environment.rb \
example_package_database.rb \
example_package_id.rb \
example_mask.rb \
example_match_package.rb \
- example_query.rb \
example_repository.rb \
example_version_operator.rb \
example_version_spec.rb
diff --git a/doc/api/ruby/example_action.rb b/doc/api/ruby/example_action.rb
index ca299c2f1..f1d754ed2 100644
--- a/doc/api/ruby/example_action.rb
+++ b/doc/api/ruby/example_action.rb
@@ -17,9 +17,8 @@ exit_status = 0
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)
+ids = env[Selection::AllVersionsSorted.new(Generator::Matches.new(
+ Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])))]
# For each ID:
ids.each do | id |
diff --git a/doc/api/ruby/example_contents.rb b/doc/api/ruby/example_contents.rb
index 702085067..c6a4b9b5d 100644
--- a/doc/api/ruby/example_contents.rb
+++ b/doc/api/ruby/example_contents.rb
@@ -17,10 +17,9 @@ exit_status = 0
env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment)
# Fetch package IDs for installed 'sys-apps/paludis'
-ids = env.package_database.query(
- Query::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])) &
- Query::SupportsInstalledAction.new,
- QueryOrder::OrderByVersion)
+ids = env[Selection::AllVersionsSorted.new(
+ Generator::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])) |
+ Filter::SupportsAction.new(InstalledAction))]
# For each ID:
ids.each do | id |
diff --git a/doc/api/ruby/example_dep_spec.rb b/doc/api/ruby/example_dep_spec.rb
deleted file mode 100644
index 29b0e4acd..000000000
--- a/doc/api/ruby/example_dep_spec.rb
+++ /dev/null
@@ -1,101 +0,0 @@
-#!/usr/bin/env ruby
-# vim: set sw=4 sts=4 et tw=100 :
-
-=begin description
-This example demonstrates how to handle dependency specs.
-=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)
-
-# For each command line parameter:
-ARGV.each do | arg |
- # Create a PackageDepSpec from the parameter. The second parameter should be either
- # an empty array or [:allow_wildcards].
- spec = Paludis::parse_user_package_dep_spec(arg, [:allow_wildcards])
-
- # Display information about the PackageDepSpec.
- puts "Information about '#{spec}':"
-
- if spec.package
- puts " Package: #{spec.package}"
- end
-
- if spec.category_name_part
- puts " Category part: #{spec.category_name_part}"
- end
-
- if spec.package_name_part
- puts " Package part: #{spec.package_name_part}"
- end
-
- if spec.version_requirements and not spec.version_requirements.empty?
- print " Version requirements: "
- need_join = false
- spec.version_requirements.each do | r |
- if need_join
- case spec.version_requirements_mode
- when VersionRequirementsMode::And
- print " and "
- when VersionRequirementsMode::Or
- print " or "
- end
- end
-
- print r[:operator], r[:spec]
- need_join = true
- end
- puts
- end
-
- if spec.slot
- puts " Slot: #{spec.slot}"
- end
-
- if spec.repository
- puts " Repository: #{spec.repository}"
- end
-
- if spec.use_requirements and not spec.use_requirements.empty?
- print " Use requirements: "
- need_join = false
- spec.use_requirements.each do | u |
- if need_join
- print " and "
- end
-
- if not u[:state]
- print "-"
- end
-
- print u[:flag]
- need_join = true;
- end
- puts
- end
-
- # And display packages matching that spec
- print " Matches: "
- ids = env.package_database.query(Query::Matches.new(spec), QueryOrder::OrderByVersion)
- need_indent = false
- ids.each do | id |
- if need_indent
- puts
- print " "
- end
- print id
- need_indent = true
- end
- puts
- puts
-end
-
-exit exit_status
-
diff --git a/doc/api/ruby/example_dep_tree.rb b/doc/api/ruby/example_dep_tree.rb
index 40acc9650..bddbdcccd 100644
--- a/doc/api/ruby/example_dep_tree.rb
+++ b/doc/api/ruby/example_dep_tree.rb
@@ -115,8 +115,8 @@ end
env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment)
# Fetch package IDs for all installed packages.
-ids = env.package_database.query(
- Query::SupportsInstalledAction.new, QueryOrder::OrderByVersion)
+ids = env[Selection::AllVersionsSorted.new(
+ Generator::All.new | Filter::SupportsAction.new(InstalledAction))]
# Our results table, mapping the ID to { :has_dep => ?, :has_ext => ? }
results = { }
diff --git a/doc/api/ruby/example_environment.rb b/doc/api/ruby/example_environment.rb
index 888522eb1..80b5b0fde 100644
--- a/doc/api/ruby/example_environment.rb
+++ b/doc/api/ruby/example_environment.rb
@@ -23,17 +23,16 @@ exit_status = 0
# 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:
+# 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. The [] operator, for selections, is covered
+# in other examples. 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
@@ -41,13 +40,13 @@ else
end
# And use flags, for which we need package IDs:
-ids = env.package_database.query(
- Query::Matches.new(Paludis::parse_user_package_dep_spec('sys-apps/paludis', [])) &
- Query::SupportsInstalledAction.new,
- QueryOrder::OrderByVersion)
+ids = env[Selection::AllVersionsSorted.new(
+ Generator::Matches.new(Paludis::parse_user_package_dep_spec('sys-apps/paludis', [])) |
+ Filter::SupportsAction.new(InstalledAction))]
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
+
diff --git a/doc/api/ruby/example_mask.rb b/doc/api/ruby/example_mask.rb
index 121305173..19c0a6bcc 100644
--- a/doc/api/ruby/example_mask.rb
+++ b/doc/api/ruby/example_mask.rb
@@ -17,9 +17,8 @@ exit_status = 0
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)
+ids = env[Selection::AllVersionsSorted.new(
+ Generator::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])))]
# For each ID:
ids.each do | id |
diff --git a/doc/api/ruby/example_match_package.rb b/doc/api/ruby/example_match_package.rb
index 0c0d3592c..61788d1ac 100644
--- a/doc/api/ruby/example_match_package.rb
+++ b/doc/api/ruby/example_match_package.rb
@@ -17,7 +17,8 @@ exit_status = 0
env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment)
# Fetch all installed packages
-ids = env.package_database.query(Query::SupportsInstalledAction.new, QueryOrder::OrderByVersion);
+ids = env[Selection::AllVersionsSorted.new(
+ Generator::All.new | Filter::SupportsAction.new(InstalledAction))]
# Fetch the 'system' and 'world' sets. Ordinarily we should check for
# Nil here, but these two sets will always exist.
diff --git a/doc/api/ruby/example_package_database.rb b/doc/api/ruby/example_package_database.rb
index 913d20277..5201d4d8d 100644
--- a/doc/api/ruby/example_package_database.rb
+++ b/doc/api/ruby/example_package_database.rb
@@ -16,8 +16,7 @@ exit_status = 0
# We start with an Environment, respecting the user's '--environment' choice.
env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment)
-# The most useful PackageDatabase method is PackageDatabase::query,
-# which is covered in other examples. But there are others:
+# Mostly PackageDatabase is used by Environment. But other methods are useful:
if env.package_database.has_repository_named?('gentoo')
repo = env.package_database.fetch_repository('gentoo')
puts "Repository 'gentoo' exists, and has format '" +
diff --git a/doc/api/ruby/example_package_id.rb b/doc/api/ruby/example_package_id.rb
index 68e48dedf..8fa10a991 100644
--- a/doc/api/ruby/example_package_id.rb
+++ b/doc/api/ruby/example_package_id.rb
@@ -19,9 +19,8 @@ exit_status = 0
env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment)
# Fetch package IDs for installed 'sys-apps/paludis'
-ids = env.package_database.query(
- Query::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])),
- QueryOrder::OrderByVersion)
+ids = env[Selection::AllVersionsSorted.new(
+ Generator::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])))]
# For each ID:
ids.each do | id |
@@ -69,10 +68,6 @@ ids.each do | id |
puts " Actions: ".ljust(40) + actions.join(' ')
- # And various misc methods. Clients don't usually use these
- # directly.
- puts " breaks_portage?: ".ljust(40) + id.breaks_portage?.to_s
-
puts
end
diff --git a/doc/api/ruby/example_query.rb b/doc/api/ruby/example_query.rb
deleted file mode 100644
index 3eecc0b8a..000000000
--- a/doc/api/ruby/example_query.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/usr/bin/env ruby
-# vim: set sw=4 sts=4 et tw=100 :
-
-=begin description
-This example demonstrates how use the standard Query classes.
-=end
-
-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(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])))
-
-# 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(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])) &
- Query::SupportsInstalledAction.new)
-
-# Usually Query::NotMasked should be combined with Query::SupportsInstallAction,
-# since installed packages aren't masked.
-show_query(env,
- Query::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])) &
- Query::SupportsInstallAction.new &
- Query::NotMasked.new)
-