aboutsummaryrefslogtreecommitdiff
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
parentc1eec2f615c0b9c7bfb10ee542c8dd1c6a51129b (diff)
downloadpaludis-61c8bcc3acc217ffcf296e229512bdd362b80093.tar.gz
paludis-61c8bcc3acc217ffcf296e229512bdd362b80093.tar.xz
Start working on ruby.
-rw-r--r--doc/api/index.html.part146
-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
-rw-r--r--doc/paludis.css13
-rw-r--r--ruby/Makefile.am46
-rw-r--r--ruby/action.cc294
-rw-r--r--ruby/action_TEST.rb86
-rw-r--r--ruby/package_id.cc43
-rw-r--r--ruby/package_id_TEST.rb14
-rw-r--r--ruby/paludis_ruby.hh2
12 files changed, 755 insertions, 24 deletions
diff --git a/doc/api/index.html.part b/doc/api/index.html.part
index f2d5d1c..6fddf49 100644
--- a/doc/api/index.html.part
+++ b/doc/api/index.html.part
@@ -12,3 +12,149 @@
</ul>
</li>
</ul>
+
+<h2>Examples</h2>
+
+<p>There are examples showing how to use various classes. Many examples are available in more than one language, showing
+how concepts map on to different language bindings.</p>
+
+<table summary="Examples, in different languages">
+ <tr>
+ <th>Example</th>
+ <th colspan="3">Language</th>
+ </tr>
+
+ <tr>
+ <td>example_about</td>
+ <td><a href="cplusplus/example__about_8cc-example.html">C++</a></td>
+ <td><a href="ruby/example_about.html">Ruby</a></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_action</td>
+ <td><a href="cplusplus/example__action_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_contents</td>
+ <td><a href="cplusplus/example__contents_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_dep_label</td>
+ <td><a href="cplusplus/example__dep__label_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_dep_spec</td>
+ <td><a href="cplusplus/example__dep__spec_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_dep_spec_flattener</td>
+ <td><a href="cplusplus/example__dep__spec__flattener_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_dep_tag</td>
+ <td><a href="cplusplus/example__dep__tag_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_dep_tree</td>
+ <td><a href="cplusplus/example__dep__tree_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_environment</td>
+ <td><a href="cplusplus/example__environment_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_formatter</td>
+ <td><a href="cplusplus/example__formatter_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_mask</td>
+ <td><a href="cplusplus/example__mask_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_match_package</td>
+ <td><a href="cplusplus/example__match__package_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_metadata_key</td>
+ <td><a href="cplusplus/example__metadata__key_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_name</td>
+ <td><a href="cplusplus/example__name_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_package_database</td>
+ <td><a href="cplusplus/example__package__database_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_package_id</td>
+ <td><a href="cplusplus/example__package__id_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_query</td>
+ <td><a href="cplusplus/example__query_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_query_delegate</td>
+ <td><a href="cplusplus/example__query__delegate_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_repository</td>
+ <td><a href="cplusplus/example__repository_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_stringify_formatter</td>
+ <td><a href="cplusplus/example__stringify__formatter_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_version_operator</td>
+ <td><a href="cplusplus/example__version__operator_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>example_version_spec</td>
+ <td><a href="cplusplus/example__version__spec_8cc-example.html">C++</a></td>
+ <td></td>
+ <td></td>
+ </tr>
+</table>
+
diff --git a/doc/api/ruby/Makefile.am b/doc/api/ruby/Makefile.am
index bcce789..cfc0936 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 0000000..760e479
--- /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 0000000..962db8b
--- /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 0000000..7352e8c
--- /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
+
diff --git a/doc/paludis.css b/doc/paludis.css
index 4935a97..c209430 100644
--- a/doc/paludis.css
+++ b/doc/paludis.css
@@ -137,3 +137,16 @@ code {
background-color: #ffeedd;
}
+div.main table {
+ border-width: 0px;
+}
+
+div.main th, div.main td {
+ border: 1px solid #996600;
+}
+
+div.main th {
+ text-align: left;
+ font-weight: bold;
+}
+
diff --git a/ruby/Makefile.am b/ruby/Makefile.am
index dcf53fc..0414a26 100644
--- a/ruby/Makefile.am
+++ b/ruby/Makefile.am
@@ -17,40 +17,42 @@ CLEANFILES = *~ gmon.out *.gcov *.gcno *.gcda *.o Paludis.so .libs/Paludis.so
MAINTAINERCLEANFILES = Makefile.in
IF_RUBY_TESTS = \
- query_TEST.rb \
- find_unused_packages_task_TEST.rb \
- package_database_TEST.rb \
- log_TEST.rb \
- version_spec_TEST.rb \
- dep_spec_TEST.rb \
- qualified_package_name_TEST.rb \
+ action_TEST.rb \
contents_TEST.rb \
dep_list_TEST.rb \
- repository_TEST.rb \
+ dep_spec_TEST.rb \
+ dep_tag_TEST.rb \
environment_TEST.rb \
+ find_unused_packages_task_TEST.rb \
+ log_TEST.rb \
+ package_database_TEST.rb \
+ package_id_TEST.rb \
paludis_ruby_TEST.rb \
- dep_tag_TEST.rb \
- package_id_TEST.rb
+ qualified_package_name_TEST.rb \
+ query_TEST.rb \
+ repository_TEST.rb \
+ version_spec_TEST.rb
IF_RUBY_QA_TESTS = \
qa_TEST.rb
IF_RUBY_SOURCES = \
paludis_ruby.cc paludis_ruby.hh \
- environment.cc \
- version_spec.cc \
+ action.cc \
+ contents.cc \
+ dep_list.cc \
dep_spec.cc \
+ dep_tag.cc \
+ environment.cc \
+ find_unused_packages_task.cc \
log.cc \
+ name.cc \
package_database.cc \
- repository.cc \
package_id.cc \
qualified_package_name.cc \
- contents.cc \
- dep_list.cc \
- dep_tag.cc \
query.cc \
- find_unused_packages_task.cc \
- name.cc
+ repository.cc \
+ version_spec.cc
IF_RUBY_QA_SOURCES = \
qa.cc
@@ -58,13 +60,13 @@ IF_RUBY_QA_SOURCES = \
EXTRA_DIST = $(IF_RUBY_TESTS) $(IF_RUBY_SOURCES) \
$(IF_RUBY_QA_TESTS) $(IF_RUBY_QA_SOURCES) \
paludis_ruby_so.cc \
+ dep_list_TEST_setup.sh dep_list_TEST_cleanup.sh \
environment_TEST_setup.sh environment_TEST_cleanup.sh \
- package_id_TEST_setup.sh package_id_TEST_cleanup.sh \
+ find_unused_packages_task_TEST_setup.sh find_unused_packages_task_TEST_cleanup.sh \
package_database_TEST_setup.sh package_database_TEST_cleanup.sh \
- repository_TEST_setup.sh repository_TEST_cleanup.sh \
+ package_id_TEST_setup.sh package_id_TEST_cleanup.sh \
paludis_ruby_TEST_setup.sh paludis_ruby_TEST_cleanup.sh \
- dep_list_TEST_setup.sh dep_list_TEST_cleanup.sh \
- find_unused_packages_task_TEST_setup.sh find_unused_packages_task_TEST_cleanup.sh
+ repository_TEST_setup.sh repository_TEST_cleanup.sh
TESTS_ENVIRONMENT = env \
TEST_OUTPUT_WRAPPER="`$(top_srcdir)/paludis/repositories/e/ebuild/utils/canonicalise $(top_builddir)/paludis/util/outputwrapper`" \
diff --git a/ruby/action.cc b/ruby/action.cc
new file mode 100644
index 0000000..1a0b74b
--- /dev/null
+++ b/ruby/action.cc
@@ -0,0 +1,294 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Ciaran McCreesh
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <paludis_ruby.hh>
+#include <paludis/action.hh>
+#include <ruby.h>
+
+using namespace paludis;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_supports_action_test_base;
+ static VALUE c_supports_fetch_action_test;
+
+ static VALUE c_action;
+ static VALUE c_fetch_action;
+ static VALUE c_fetch_action_options;
+
+ const FetchActionOptions
+ value_to_fetch_action_options(VALUE v)
+ {
+ if (rb_obj_is_kind_of(v, c_fetch_action_options))
+ {
+ FetchActionOptions * v_ptr;
+ Data_Get_Struct(v, FetchActionOptions, v_ptr);
+ return *v_ptr;
+ }
+ else
+ {
+ rb_raise(rb_eTypeError, "Can't convert %s into FetchActionOptions", rb_obj_classname(v));
+ }
+ }
+
+ VALUE
+ fetch_action_options_to_value(const FetchActionOptions & m)
+ {
+ FetchActionOptions * m_ptr(new FetchActionOptions(m));
+ try
+ {
+ return Data_Wrap_Struct(c_fetch_action_options, 0, &Common<FetchActionOptions>::free, m_ptr);
+ }
+ catch (const std::exception & e)
+ {
+ delete m_ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ supports_fetch_action_init(int, VALUE *, VALUE self)
+ {
+ return self;
+ }
+
+ VALUE
+ fetch_action_init(int, VALUE *, VALUE self)
+ {
+ return self;
+ }
+
+ VALUE
+ fetch_action_options_init(int, VALUE *, VALUE self)
+ {
+ return self;
+ }
+
+ /*
+ * call-seq:
+ * SupportsFetchActionTest.new -> SupportsFetchActionTest
+ */
+ VALUE
+ supports_fetch_action_test_new(VALUE self)
+ {
+ tr1::shared_ptr<const SupportsActionTestBase> * a(
+ new tr1::shared_ptr<const SupportsActionTestBase>(new SupportsActionTest<FetchAction>));
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<tr1::shared_ptr<const SupportsActionTestBase> >::free, a));
+ rb_obj_call_init(tdata, 0, &self);
+ return tdata;
+ }
+
+ /*
+ * call-seq:
+ * FetchActionOptions.new(fetch_unneeded, safe_resume) -> FetchActionOptions
+ * FetchActionOptions.new(Hash) -> FetchActionOptions
+ *
+ * FetchActionOptions.new can either be called with all parameters in order, or with one hash
+ * parameter, where the hash keys are symbols with the names above.
+ */
+ VALUE
+ fetch_action_options_new(int argc, VALUE *argv, VALUE self)
+ {
+ FetchActionOptions * ptr(0);
+ try
+ {
+ bool v_fetch_unneeded;
+ bool v_safe_resume;
+
+ if (1 == argc && rb_obj_is_kind_of(argv[0], rb_cHash))
+ {
+ if (Qnil == rb_hash_aref(argv[0], ID2SYM(rb_intern("fetch_unneeded"))))
+ rb_raise(rb_eArgError, "Missing Parameter: fetch_unneeded");
+ if (Qnil == rb_hash_aref(argv[0], ID2SYM(rb_intern("safe_resume"))))
+ rb_raise(rb_eArgError, "Missing Parameter: safe_resume");
+ v_fetch_unneeded =
+ rb_hash_aref(argv[0], ID2SYM(rb_intern("fetch_unneeded"))) != Qfalse;
+ v_safe_resume =
+ rb_hash_aref(argv[0], ID2SYM(rb_intern("safe_resume"))) != Qfalse;
+ }
+ else if (2 == argc)
+ {
+ v_fetch_unneeded = argv[0] != Qfalse;
+ v_safe_resume = argv[1] != Qfalse;
+ }
+ else
+ {
+ rb_raise(rb_eArgError, "FetchActionOptions expects one or two arguments, but got %d",argc);
+ }
+
+ ptr = new FetchActionOptions(FetchActionOptions::create()
+ .fetch_unneeded(v_fetch_unneeded)
+ .safe_resume(v_safe_resume)
+ );
+
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<FetchActionOptions>::free, ptr));
+ rb_obj_call_init(tdata, argc, argv);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
+ * Document-method: fetch_unneeded
+ *
+ * call-seq:
+ * fetch_unneeded -> true or false
+ */
+ VALUE
+ fetch_action_options_fetch_unneeded(VALUE self)
+ {
+ FetchActionOptions * p;
+ Data_Get_Struct(self, FetchActionOptions, p);
+ return p->fetch_unneeded ? Qtrue : Qfalse;
+ }
+
+ /*
+ * Document-method: safe_resume
+ *
+ * call-seq:
+ * safe_resume -> true or false
+ */
+ VALUE
+ fetch_action_options_safe_resume(VALUE self)
+ {
+ FetchActionOptions * p;
+ Data_Get_Struct(self, FetchActionOptions, p);
+ return p->safe_resume ? Qtrue : Qfalse;
+ }
+
+ /*
+ * call-seq:
+ * FetchAction.new -> FetchAction
+ */
+ VALUE
+ fetch_action_new(VALUE self, VALUE opts)
+ {
+ const FetchActionOptions opts_ptr(value_to_fetch_action_options(opts));
+ tr1::shared_ptr<Action> * a(
+ new tr1::shared_ptr<Action>(new FetchAction(opts_ptr)));
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<tr1::shared_ptr<Action> >::free, a));
+ rb_obj_call_init(tdata, 1, &self);
+ return tdata;
+ }
+
+ /*
+ * call-seq:
+ * options -> FetchActionOptions
+ *
+ * Our FetchActionOptions.
+ */
+ VALUE
+ fetch_action_options(VALUE self)
+ {
+ tr1::shared_ptr<Action> * p;
+ Data_Get_Struct(self, tr1::shared_ptr<Action>, p);
+ return fetch_action_options_to_value(tr1::static_pointer_cast<FetchAction>(*p)->options);
+ }
+
+ void do_register_action()
+ {
+ /*
+ * Document-class: Paludis::SupportsActionTestBase
+ *
+ * Base class for action tests, used by Paludis::PackageID#supports_action.
+ */
+ c_supports_action_test_base = rb_define_class_under(paludis_module(), "SupportsActionTestBase", rb_cObject);
+ rb_funcall(c_supports_action_test_base, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ /*
+ * Document-class: Paludis::SupportsFetchActionTest
+ *
+ * Tests whether a Paludis::PackageID supports a Paludis::FetchAction.
+ */
+ c_supports_fetch_action_test = rb_define_class_under(paludis_module(), "SupportsFetchActionTest", c_supports_action_test_base);
+ rb_define_singleton_method(c_supports_fetch_action_test, "new", RUBY_FUNC_CAST((&supports_fetch_action_test_new)), 0);
+ rb_define_method(c_supports_fetch_action_test, "initialize", RUBY_FUNC_CAST(&supports_fetch_action_init), -1);
+
+ /*
+ * Document-class: Paludis::Action
+ *
+ * Base class for actions, used by Paludis::PackageID#perform_action.
+ */
+ c_action = rb_define_class_under(paludis_module(), "Action", rb_cObject);
+ rb_funcall(c_action, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ /*
+ * Document-class: Paludis::FetchAction
+ *
+ * An action for fetching.
+ */
+ c_fetch_action = rb_define_class_under(paludis_module(), "FetchAction", c_action);
+ rb_define_singleton_method(c_fetch_action, "new", RUBY_FUNC_CAST(&fetch_action_new), 1);
+ rb_define_method(c_fetch_action, "initialize", RUBY_FUNC_CAST(&fetch_action_init), -1);
+ rb_define_method(c_fetch_action, "options", RUBY_FUNC_CAST(&fetch_action_options), 0);
+
+ /*
+ * Document-class: Paludis::FetchActionOptions
+ *
+ * Options for Paludis::FetchAction.
+ */
+ c_fetch_action_options = rb_define_class_under(paludis_module(), "FetchActionOptions", rb_cObject);
+ rb_define_singleton_method(c_fetch_action_options, "new", RUBY_FUNC_CAST(&fetch_action_options_new), -1);
+ rb_define_method(c_fetch_action_options, "initialize", RUBY_FUNC_CAST(&fetch_action_options_init), -1);
+ rb_define_method(c_fetch_action_options, "fetch_unneeded", RUBY_FUNC_CAST(&fetch_action_options_fetch_unneeded), 0);
+ rb_define_method(c_fetch_action_options, "safe_resume", RUBY_FUNC_CAST(&fetch_action_options_safe_resume), 0);
+ }
+}
+
+tr1::shared_ptr<const SupportsActionTestBase>
+paludis::ruby::value_to_supports_action_test_base(VALUE v)
+{
+ if (rb_obj_is_kind_of(v, c_supports_action_test_base))
+ {
+ tr1::shared_ptr<const SupportsActionTestBase> * v_ptr;
+ Data_Get_Struct(v, tr1::shared_ptr<const SupportsActionTestBase>, v_ptr);
+ return *v_ptr;
+ }
+ else
+ {
+ rb_raise(rb_eTypeError, "Can't convert %s into SupportsActionTestBase", rb_obj_classname(v));
+ }
+
+}
+
+tr1::shared_ptr<Action>
+paludis::ruby::value_to_action(VALUE v)
+{
+ if (rb_obj_is_kind_of(v, c_action))
+ {
+ tr1::shared_ptr<Action> * v_ptr;
+ Data_Get_Struct(v, tr1::shared_ptr<Action>, v_ptr);
+ return *v_ptr;
+ }
+ else
+ {
+ rb_raise(rb_eTypeError, "Can't convert %s into Action", rb_obj_classname(v));
+ }
+}
+
+RegisterRubyClass::Register paludis_ruby_register_action PALUDIS_ATTRIBUTE((used))
+ (&do_register_action);
+
diff --git a/ruby/action_TEST.rb b/ruby/action_TEST.rb
new file mode 100644
index 0000000..8c9d692
--- /dev/null
+++ b/ruby/action_TEST.rb
@@ -0,0 +1,86 @@
+#!/usr/bin/env ruby
+# vim: set sw=4 sts=4 et tw=80 :
+#
+# Copyright (c) 2007 Ciaran McCreesh
+#
+# This file is part of the Paludis package manager. Paludis is free software;
+# you can redistribute it and/or modify it under the terms of the GNU General
+# Public License version 2, as published by the Free Software Foundation.
+#
+# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+# Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+require 'test/unit'
+require 'Paludis'
+
+module Paludis
+ class TestCase_SupportsActionTestBase < Test::Unit::TestCase
+ def test_no_create
+ assert_raise NoMethodError do
+ ce = SupportsActionTestBase.new('test')
+ end
+ end
+ end
+
+ class TestCase_SupportsFetchActionTest < Test::Unit::TestCase
+ def test_create
+ assert_kind_of SupportsFetchActionTest, SupportsFetchActionTest.new
+ assert_kind_of SupportsActionTestBase, SupportsFetchActionTest.new
+ end
+ end
+
+ class TestCase_Action < Test::Unit::TestCase
+ def test_no_create
+ assert_raise NoMethodError do
+ ce = Action.new('test')
+ end
+ end
+ end
+
+ class TestCase_FetchActionOptions < Test::Unit::TestCase
+ def test_create
+ assert_kind_of FetchActionOptions, FetchActionOptions.new(false, false)
+ assert_kind_of FetchActionOptions, FetchActionOptions.new(
+ {:safe_resume => false, :fetch_unneeded => false})
+ end
+ end
+
+ class TestCase_FetchAction < Test::Unit::TestCase
+ def test_create
+ assert_kind_of FetchAction, FetchAction.new(FetchActionOptions.new(false, false))
+ assert_kind_of Action, FetchAction.new(FetchActionOptions.new(false, false))
+
+ assert_kind_of FetchAction, FetchAction.new(FetchActionOptions.new(
+ {:safe_resume => false, :fetch_unneeded => false}))
+ end
+
+ def test_bad_create
+ assert_raise TypeError do
+ FetchAction.new("foo")
+ end
+
+ assert_raise ArgumentError do
+ FetchAction.new(FetchActionOptions.new({:monkey => false}))
+ end
+ end
+
+ def test_options
+ a = FetchAction.new(FetchActionOptions.new(false, true))
+ assert_equal a.options.fetch_unneeded, false
+ assert_equal a.options.safe_resume, true
+
+ a = FetchAction.new(FetchActionOptions.new({:safe_resume => false, :fetch_unneeded => true}))
+ assert_equal a.options.fetch_unneeded, true
+ assert_equal a.options.safe_resume, false
+ end
+ end
+end
+
+
diff --git a/ruby/package_id.cc b/ruby/package_id.cc
index ddeb769..70c97f0 100644
--- a/ruby/package_id.cc
+++ b/ruby/package_id.cc
@@ -2,6 +2,7 @@
/*
* Copyright (c) 2007 Richard Brown
+ * Copyright (c) 2007 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -186,6 +187,45 @@ namespace
}
/*
+ * call-seq:
+ * supports_action(action_test) -> true or false
+ *
+ * Returns whether we support an action.
+ */
+ VALUE
+ package_id_supports_action(VALUE self, VALUE test)
+ {
+ tr1::shared_ptr<const PackageID> * self_ptr;
+ tr1::shared_ptr<const SupportsActionTestBase> test_ptr(value_to_supports_action_test_base(test));
+ Data_Get_Struct(self, tr1::shared_ptr<const PackageID>, self_ptr);
+ return (*self_ptr)->supports_action(*test_ptr) ? Qtrue : Qfalse;
+ }
+
+ /*
+ * call-seq:
+ * perform_action(action) -> Nil
+ *
+ * Perform an action.
+ */
+ VALUE
+ package_id_perform_action(VALUE self, VALUE test)
+ {
+ tr1::shared_ptr<const PackageID> * self_ptr;
+ tr1::shared_ptr<Action> a_ptr(value_to_action(test));
+ Data_Get_Struct(self, tr1::shared_ptr<const PackageID>, self_ptr);
+ try
+ {
+ (*self_ptr)->perform_action(*a_ptr);
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+
+ return Qnil;
+ }
+
+ /*
* Document-method: slot
*
* call-seq:
@@ -535,6 +575,9 @@ namespace
rb_define_method(c_package_id, "repository_name", RUBY_FUNC_CAST(&package_id_repository_name), 0);
rb_define_method(c_package_id, "==", RUBY_FUNC_CAST(&package_id_equal), 1);
rb_define_method(c_package_id, "[]", RUBY_FUNC_CAST(&package_id_subscript), 1);
+ rb_define_method(c_package_id, "to_s", RUBY_FUNC_CAST(&Common<tr1::shared_ptr<const PackageID> >::to_s_via_ptr), 0);
+ rb_define_method(c_package_id, "supports_action", RUBY_FUNC_CAST(&package_id_supports_action), 1);
+ rb_define_method(c_package_id, "perform_action", RUBY_FUNC_CAST(&package_id_perform_action), 1);
rb_define_method(c_package_id, "each_metadata", RUBY_FUNC_CAST(&package_id_each_metadata), 0);
rb_define_method(c_package_id, "keywords_key", RUBY_FUNC_CAST((&KeyValue<MetadataSetKey<KeywordNameSet>,&PackageID::keywords_key>::fetch)), 0);
rb_define_method(c_package_id, "iuse_key", RUBY_FUNC_CAST((&KeyValue<MetadataSetKey<IUseFlagSet>,&PackageID::iuse_key>::fetch)), 0);
diff --git a/ruby/package_id_TEST.rb b/ruby/package_id_TEST.rb
index f7a6332..ad1851a 100644
--- a/ruby/package_id_TEST.rb
+++ b/ruby/package_id_TEST.rb
@@ -120,6 +120,20 @@ module Paludis
assert_equal 'foo/bar::testrepo', pid_testrepo.canonical_form(PackageIDCanonicalForm::NoVersion)
end
+ def test_stringify
+ assert_equal 'foo/bar-1.0::testrepo', "#{pid_testrepo}"
+ end
+
+ def test_supports_action_test
+ assert pid_testrepo.supports_action(SupportsFetchActionTest.new)
+ assert_raise TypeError do
+ pid_testrepo.supports_action(1)
+ end
+ assert_raise TypeError do
+ pid_testrepo.supports_action(pid_testrepo)
+ end
+ end
+
def test_=
assert_equal pid_testrepo, pid_testrepo
end
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index 6a0be8b..6cce689 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -100,6 +100,8 @@ namespace paludis
RepositoryEInterface::ProfilesDescLine value_to_profiles_desc_line(VALUE v);
Query value_to_query(VALUE v);
tr1::shared_ptr<Repository> value_to_repository(VALUE);
+ tr1::shared_ptr<const SupportsActionTestBase> value_to_supports_action_test_base(VALUE v);
+ tr1::shared_ptr<Action> value_to_action(VALUE v);
#ifdef ENABLE_RUBY_QA
QACheckProperties value_to_qa_check_properties(VALUE);