aboutsummaryrefslogtreecommitdiff
path: root/doc/api/ruby
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-11-06 12:08:47 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-11-06 12:08:47 +0000
commit61c8bcc3acc217ffcf296e229512bdd362b80093 (patch)
treeec7eaf1c501e620b58911bd233bad0a7526a2349 /doc/api/ruby
parentc1eec2f615c0b9c7bfb10ee542c8dd1c6a51129b (diff)
downloadpaludis-61c8bcc3acc217ffcf296e229512bdd362b80093.tar.gz
paludis-61c8bcc3acc217ffcf296e229512bdd362b80093.tar.xz
Start working on ruby.
Diffstat (limited to 'doc/api/ruby')
-rw-r--r--doc/api/ruby/Makefile.am13
-rw-r--r--doc/api/ruby/example_about.rb14
-rw-r--r--doc/api/ruby/example_action.rb78
-rw-r--r--doc/api/ruby/example_command_line.rb30
4 files changed, 133 insertions, 2 deletions
diff --git a/doc/api/ruby/Makefile.am b/doc/api/ruby/Makefile.am
index bcce78913..cfc093634 100644
--- a/doc/api/ruby/Makefile.am
+++ b/doc/api/ruby/Makefile.am
@@ -21,16 +21,25 @@ htmldocs-local : $(paludisapirubyhtml_DATA)
dist_noinst_SCRIPTS = create_ruby_doc.rb
+examples = \
+ example_command_line.rb \
+ example_about.rb \
+ example_action.rb
+
+EXTRA_DIST = $(examples)
+
if ENABLE_RUBY
all-local : rdoc
rdoc : ruby
-ruby : create_ruby_doc.rb
+ruby : create_ruby_doc.rb $(examples)
rm -fr ruby
env TOP_SRCDIR="$(top_srcdir)" $(RUBY) \
- $(srcdir)/create_ruby_doc.rb -t "Paludis Ruby API" -m Paludis --op ruby $(top_srcdir)/ruby/*.cc
+ $(srcdir)/create_ruby_doc.rb -t "Paludis Ruby API" -m Paludis --op ruby \
+ $(top_srcdir)/ruby/*.cc \
+ $(srcdir)/example_*.rb
install-data-local :
mkdir -p $(DESTDIR)$(htmldir)/api
diff --git a/doc/api/ruby/example_about.rb b/doc/api/ruby/example_about.rb
new file mode 100644
index 000000000..760e47992
--- /dev/null
+++ b/doc/api/ruby/example_about.rb
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+# vim: set sw=4 sts=4 et tw=80 :
+
+require 'Paludis'
+
+print "Built using Paludis ", Paludis::VersionMajor, ".", Paludis::VersionMinor,
+ ".", Paludis::VersionMinor, Paludis::VersionSuffix
+
+if not Paludis::SubversionRevision.empty?
+ print Paludis::SubversionRevision
+end
+
+print "\n"
+
diff --git a/doc/api/ruby/example_action.rb b/doc/api/ruby/example_action.rb
new file mode 100644
index 000000000..962db8bd3
--- /dev/null
+++ b/doc/api/ruby/example_action.rb
@@ -0,0 +1,78 @@
+#!/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 'sys-apps/paludis'
+ids = env.package_database.query(
+ Query::Matches.new(PackageDepSpec.new("sys-apps/paludis", PackageDepSpecParseMode::Permissive)),
+ QueryOrder::OrderByVersion)
+
+# For each ID:
+ids.each do | id |
+ # Do we support a FetchAction? We find out by creating a SupportsFetchActionTest object, and
+ # querying via the PackageID#supports_action method.
+ supports_fetch_action = SupportsFetchActionTest.new
+ if not id.supports_action(supports_fetch_action)
+ puts "ID #{id} does not support the fetch action."
+ else
+ puts "ID #{id} supports the fetch action, trying to fetch:"
+
+ # Carry out a FetchAction. We need to specify various options when creating a FetchAction,
+ # controlling whether safe resume is used and whether unneeded (e.g. due to disabled USE
+ # flags) source files should still be fetched.
+ fetch_action = FetchAction.new(FetchActionOptions.new({
+ :fetch_unneeded => false,
+ :safe_resume => true
+ }))
+
+### begin
+ id.perform_action(fetch_action)
+
+### rescue FetchActionError => e
+### exit_status |= 1
+### puts "Caught FetchActionError, with the following details:"
+###
+### e.failures.each do | f |
+### print " * File '#{f.target_file}': "
+### need_comma = false
+###
+### if f.requires_manual_fetching
+### print "requires manual fetching"
+### need_comma = true
+### end
+###
+### if f.failed_automatic_fetching
+### if need_comma
+### print ", "
+### end
+### print "failed automatic fetching"
+### need_comma = true
+### end
+###
+### if not f.failed_integrity_checks.empty?
+### if need_comma
+### print ", "
+### end
+### print "failed integrity checks: #{f.failed_integrity_checks}"
+### need_comma = true
+### end
+### puts
+### end
+### end
+
+ end
+
+ puts
+end
+
+exit exit_status
+
diff --git a/doc/api/ruby/example_command_line.rb b/doc/api/ruby/example_command_line.rb
new file mode 100644
index 000000000..7352e8cdf
--- /dev/null
+++ b/doc/api/ruby/example_command_line.rb
@@ -0,0 +1,30 @@
+#!/usr/bin/env ruby
+# vim: set sw=4 sts=4 et tw=80 :
+
+require 'getoptlong'
+require 'singleton'
+require 'Paludis'
+
+class ExampleCommandLine < GetoptLong
+ include Singleton
+
+ def initialize
+ super(
+ [ '--log-level', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--environment', '-E', GetoptLong::REQUIRED_ARGUMENT ]
+ )
+
+ @environment = ""
+ each do | opt, arg |
+ case opt
+ when '--log-level'
+ Paludis::Log.instance.log_level = Paludis::LogLevel::Debug
+ when '--environment'
+ @environment = arg
+ end
+ end
+ end
+
+ attr_reader :environment
+end
+