aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-11-07 19:52:54 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-11-07 19:52:54 +0000
commitba9ae41ee7e6d6afd412bc2998b850b8f95d7cc9 (patch)
tree8dfb32224a34a649d9bdb817cc972c1be7ccaecc
parent8286ada8ade6fe28069ca2756f8b43fe790010af (diff)
downloadpaludis-ba9ae41ee7e6d6afd412bc2998b850b8f95d7cc9.tar.gz
paludis-ba9ae41ee7e6d6afd412bc2998b850b8f95d7cc9.tar.xz
(ruby) Add InfoAction and ConfigAction
-rw-r--r--ruby/action.cc137
-rw-r--r--ruby/action_TEST.rb40
-rw-r--r--ruby/paludis_ruby.cc20
3 files changed, 165 insertions, 32 deletions
diff --git a/ruby/action.cc b/ruby/action.cc
index 6c36000..6b247f9 100644
--- a/ruby/action.cc
+++ b/ruby/action.cc
@@ -32,12 +32,17 @@ namespace
{
static VALUE c_supports_action_test_base;
static VALUE c_supports_fetch_action_test;
+ static VALUE c_supports_info_action_test;
+ static VALUE c_supports_config_action_test;
static VALUE c_action;
static VALUE c_fetch_action;
static VALUE c_fetch_action_options;
static VALUE c_fetch_action_failure;
+ static VALUE c_info_action;
+ static VALUE c_config_action;
+
const FetchActionOptions
value_to_fetch_action_options(VALUE v)
{
@@ -84,36 +89,40 @@ namespace
}
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)
+ empty_init(int, VALUE *, VALUE self)
{
return self;
}
/*
+ * Document-method: SupportsFetchActionTest.new
+ *
* call-seq:
* SupportsFetchActionTest.new -> SupportsFetchActionTest
+ *
+ * Create new SupportsFetchActionTest object.
*/
- VALUE
- supports_fetch_action_test_new(VALUE self)
+ /*
+ * Document-method: SupportsInfoActionTest.new
+ *
+ * call-seq:
+ * SupportsInfoActionTest.new -> SupportsInfoActionTest
+ *
+ * Create new SupportsInfoActionTest object.
+ */
+ template <typename A_>
+ struct SupportsActionTestNew
{
- 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;
- }
+ static VALUE
+ supports_action_test_new(VALUE self)
+ {
+ tr1::shared_ptr<const SupportsActionTestBase> * a(
+ new tr1::shared_ptr<const SupportsActionTestBase>(new SupportsActionTest<A_>));
+ 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:
@@ -226,12 +235,6 @@ namespace
return fetch_action_options_to_value(tr1::static_pointer_cast<FetchAction>(*p)->options);
}
- VALUE
- fetch_action_failure_init(int, VALUE *, VALUE self)
- {
- return self;
- }
-
/*
* call-seq:
* FetchActionFailure.new(target_file, requires_manual_fetching, failed_automatic_fetching, failed_integrity_checks) -> FetchActionFailure
@@ -352,6 +355,35 @@ namespace
}
};
+ /*
+ * Document-method InfoAction.new
+ *
+ * call-seq:
+ * InfoAction.new -> InfoAction
+ *
+ * Create new InfoAction
+ */
+ /*
+ * Document-method ConfigAction.new
+ *
+ * call-seq:
+ * ConfigAction.new -> ConfigAction
+ *
+ * Create new ConfigAction
+ */
+ template <typename A_>
+ struct EasyActionNew
+ {
+ static VALUE
+ easy_action_new(VALUE self)
+ {
+ tr1::shared_ptr<Action> * a(new tr1::shared_ptr<Action>(new A_()));
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<tr1::shared_ptr<Action> >::free, a));
+ rb_obj_call_init(tdata, 1, &self);
+ return tdata;
+ }
+ };
+
void do_register_action()
{
/*
@@ -368,8 +400,29 @@ namespace
* 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);
+ rb_define_singleton_method(c_supports_fetch_action_test, "new",
+ RUBY_FUNC_CAST((&SupportsActionTestNew<FetchAction>::supports_action_test_new)), 0);
+ rb_define_method(c_supports_fetch_action_test, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
+
+ /*
+ * Document-class: Paludis::SupportsInfoActionTest
+ *
+ * Tests whether a Paludis::PackageID supports a Paludis::InfoAction.
+ */
+ c_supports_info_action_test = rb_define_class_under(paludis_module(), "SupportsInfoActionTest", c_supports_action_test_base);
+ rb_define_singleton_method(c_supports_info_action_test, "new",
+ RUBY_FUNC_CAST((&SupportsActionTestNew<InfoAction>::supports_action_test_new)), 0);
+ rb_define_method(c_supports_info_action_test, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
+
+ /*
+ * Document-class: Paludis::SupportsConfigActionTest
+ *
+ * Tests whether a Paludis::PackageID supports a Paludis::ConfigAction.
+ */
+ c_supports_config_action_test = rb_define_class_under(paludis_module(), "SupportsConfigActionTest", c_supports_action_test_base);
+ rb_define_singleton_method(c_supports_config_action_test, "new",
+ RUBY_FUNC_CAST((&SupportsActionTestNew<ConfigAction>::supports_action_test_new)), 0);
+ rb_define_method(c_supports_config_action_test, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
/*
* Document-class: Paludis::Action
@@ -386,7 +439,7 @@ namespace
*/
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, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
rb_define_method(c_fetch_action, "options", RUBY_FUNC_CAST(&fetch_action_options), 0);
/*
@@ -396,7 +449,7 @@ namespace
*/
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, "initialize", RUBY_FUNC_CAST(&empty_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);
@@ -407,7 +460,7 @@ namespace
*/
c_fetch_action_failure = rb_define_class_under(paludis_module(), "FetchActionFailure", rb_cObject);
rb_define_singleton_method(c_fetch_action_failure, "new", RUBY_FUNC_CAST(&fetch_action_failure_new), -1);
- rb_define_method(c_fetch_action_failure, "initialize", RUBY_FUNC_CAST(&fetch_action_failure_init), -1);
+ rb_define_method(c_fetch_action_failure, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
rb_define_method(c_fetch_action_failure, "target_file",
RUBY_FUNC_CAST((&FailureStringFetch<&FetchActionFailure::target_file>::fetch)), 0);
rb_define_method(c_fetch_action_failure, "requires_manual_fetching?",
@@ -416,6 +469,26 @@ namespace
RUBY_FUNC_CAST((&FailureBoolFetch<&FetchActionFailure::failed_automatic_fetching>::fetch)), 0);
rb_define_method(c_fetch_action_failure, "failed_integrity_checks",
RUBY_FUNC_CAST((&FailureStringFetch<&FetchActionFailure::failed_integrity_checks>::fetch)), 0);
+
+ /*
+ * Document-class: Paludis::InfoAction
+ *
+ * An action for fetching.
+ */
+ c_info_action = rb_define_class_under(paludis_module(), "InfoAction", c_action);
+ rb_define_singleton_method(c_info_action, "new",
+ RUBY_FUNC_CAST((&EasyActionNew<InfoAction>::easy_action_new)), 0);
+ rb_define_method(c_info_action, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
+
+ /*
+ * Document-class: Paludis::ConfigAction
+ *
+ * An action for fetching.
+ */
+ c_config_action = rb_define_class_under(paludis_module(), "ConfigAction", c_action);
+ rb_define_singleton_method(c_config_action, "new",
+ RUBY_FUNC_CAST((&EasyActionNew<ConfigAction>::easy_action_new)), 0);
+ rb_define_method(c_config_action, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
}
}
diff --git a/ruby/action_TEST.rb b/ruby/action_TEST.rb
index 87672d1..6409ac6 100644
--- a/ruby/action_TEST.rb
+++ b/ruby/action_TEST.rb
@@ -36,6 +36,20 @@ module Paludis
end
end
+ class TestCase_SupportsInfoActionTest < Test::Unit::TestCase
+ def test_create
+ assert_kind_of SupportsInfoActionTest, SupportsInfoActionTest.new
+ assert_kind_of SupportsActionTestBase, SupportsInfoActionTest.new
+ end
+ end
+
+ class TestCase_SupportsConfigActionTest < Test::Unit::TestCase
+ def test_create
+ assert_kind_of SupportsConfigActionTest, SupportsConfigActionTest.new
+ assert_kind_of SupportsActionTestBase, SupportsConfigActionTest.new
+ end
+ end
+
class TestCase_Action < Test::Unit::TestCase
def test_no_create
assert_raise NoMethodError do
@@ -114,6 +128,32 @@ module Paludis
assert_equal a.options.safe_resume, false
end
end
+
+ class TestCase_InfoAction < Test::Unit::TestCase
+ def test_create
+ assert_kind_of InfoAction, InfoAction.new
+ assert_kind_of Action, InfoAction.new
+ end
+
+ def test_bad_create
+ assert_raise ArgumentError do
+ InfoAction.new('')
+ end
+ end
+ end
+
+ class TestCase_ConfigAction < Test::Unit::TestCase
+ def test_create
+ assert_kind_of ConfigAction, ConfigAction.new
+ assert_kind_of Action, ConfigAction.new
+ end
+
+ def test_bad_create
+ assert_raise ArgumentError do
+ ConfigAction.new('')
+ end
+ end
+ end
end
diff --git a/ruby/paludis_ruby.cc b/ruby/paludis_ruby.cc
index 6f1c3cd..2ecc231 100644
--- a/ruby/paludis_ruby.cc
+++ b/ruby/paludis_ruby.cc
@@ -68,6 +68,8 @@ namespace
static VALUE c_downgrade_not_allowed_error;
static VALUE c_no_destination_error;
static VALUE c_fetch_action_error;
+ static VALUE c_info_action_error;
+ static VALUE c_config_action_error;
static VALUE c_action_error;
static VALUE c_environment;
@@ -182,6 +184,10 @@ void paludis::ruby::exception_to_ruby_exception(const std::exception & ee)
rb_exc_raise(rb_class_new_instance(2, ex_args, c_fetch_action_error));
}
+ else if (0 != dynamic_cast<const paludis::InfoActionError *>(&ee))
+ rb_raise(c_info_action_error, dynamic_cast<const paludis::InfoActionError *>(&ee)->message().c_str());
+ else if (0 != dynamic_cast<const paludis::ConfigActionError *>(&ee))
+ rb_raise(c_config_action_error, dynamic_cast<const paludis::ConfigActionError *>(&ee)->message().c_str());
else if (0 != dynamic_cast<const paludis::ActionError *>(&ee))
rb_raise(c_action_error, dynamic_cast<const paludis::ActionError *>(&ee)->message().c_str());
@@ -358,6 +364,20 @@ void PALUDIS_VISIBLE paludis::ruby::init()
rb_define_method(c_fetch_action_error, "initialize", RUBY_FUNC_CAST(&fetch_action_error_init), -1);
rb_define_method(c_fetch_action_error, "failures", RUBY_FUNC_CAST(&fetch_action_error_failures), 0);
+ /*
+ * Document-class: Paludis::InfoActionError
+ *
+ * Thrown if a PackageID fails to perform a InfoAction.
+ */
+ c_info_action_error = rb_define_class_under(c_paludis_module, "InfoActionError", c_action_error);
+
+ /*
+ * Document-class: Paludis::ConfigActionError
+ *
+ * Thrown if a PackageID fails to perform a ConfigAction.
+ */
+ c_config_action_error = rb_define_class_under(c_paludis_module, "ConfigActionError", c_action_error);
+
rb_define_module_function(c_paludis_module, "match_package", RUBY_FUNC_CAST(&paludis_match_package), 3);
rb_define_const(c_paludis_module, "Version", rb_str_new2((stringify(PALUDIS_VERSION_MAJOR) + "."