aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-11-08 22:40:26 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-11-08 22:40:26 +0000
commitd3e16ddedfbdd4d68b049bc2ee7bde954fd0f736 (patch)
tree0c8e67a776829f8e1385021cdbfa968aff2d7fdd
parentb76bdfdb3ac97ab58147e393f067d8f96e7e69cf (diff)
downloadpaludis-d3e16ddedfbdd4d68b049bc2ee7bde954fd0f736.tar.gz
paludis-d3e16ddedfbdd4d68b049bc2ee7bde954fd0f736.tar.xz
(ruby) Add binding for UninstallAction.
-rw-r--r--ruby/action.cc161
-rw-r--r--ruby/action_TEST.rb129
-rw-r--r--ruby/paludis_ruby.cc10
3 files changed, 279 insertions, 21 deletions
diff --git a/ruby/action.cc b/ruby/action.cc
index ae45a5b..50e4fdd 100644
--- a/ruby/action.cc
+++ b/ruby/action.cc
@@ -35,6 +35,7 @@ namespace
static VALUE c_supports_info_action_test;
static VALUE c_supports_config_action_test;
static VALUE c_supports_install_action_test;
+ static VALUE c_supports_uninstall_action_test;
static VALUE c_action;
static VALUE c_fetch_action;
@@ -49,6 +50,9 @@ namespace
static VALUE c_install_action_checks_option;
static VALUE c_install_action;
+ static VALUE c_uninstall_action_options;
+ static VALUE c_uninstall_action;
+
const bool
value_to_bool(VALUE v)
{
@@ -123,6 +127,36 @@ namespace
}
}
+ const UninstallActionOptions
+ value_to_uninstall_action_options(VALUE v)
+ {
+ if (rb_obj_is_kind_of(v, c_uninstall_action_options))
+ {
+ UninstallActionOptions * v_ptr;
+ Data_Get_Struct(v, UninstallActionOptions, v_ptr);
+ return *v_ptr;
+ }
+ else
+ {
+ rb_raise(rb_eTypeError, "Can't convert %s into UninstallActionOptions", rb_obj_classname(v));
+ }
+ }
+
+ VALUE
+ uninstall_action_options_to_value(const UninstallActionOptions & m)
+ {
+ UninstallActionOptions * m_ptr(new UninstallActionOptions(m));
+ try
+ {
+ return Data_Wrap_Struct(c_uninstall_action_options, 0, &Common<UninstallActionOptions>::free, m_ptr);
+ }
+ catch (const std::exception & e)
+ {
+ delete m_ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
const FetchActionFailure
value_to_fetch_action_failure(VALUE v)
{
@@ -161,6 +195,14 @@ namespace
* Create new SupportsInfoActionTest object.
*/
/*
+ * Document-method: SupportsConfigActionTest.new
+ *
+ * call-seq:
+ * SupportsConfigActionTest.new -> SupportsInfoActionTest
+ *
+ * Create new SupportsConfigActionTest object.
+ */
+ /*
* Document-method: SupportsInstallActionTest.new
*
* call-seq:
@@ -168,6 +210,14 @@ namespace
*
* Create new SupportsInstallActionTest object.
*/
+ /*
+ * Document-method: SupportsUninstallActionTest.new
+ *
+ * call-seq:
+ * SupportsUninstallActionTest.new -> SupportsUninstallActionTest
+ *
+ * Create new SupportsUninstallActionTest object.
+ */
template <typename A_>
struct SupportsActionTestNew
{
@@ -438,7 +488,7 @@ namespace
/*
* call-seq:
- * InstallActionOptions.new(fetch_unneeded, safe_resume) -> InstallActionOptions
+ * InstallActionOptions.new(no_config_protect, debug_build, checks, destination) -> InstallActionOptions
* InstallActionOptions.new(Hash) -> InstallActionOptions
*
* InstallActionOptions.new can either be called with all parameters in order, or with one hash
@@ -579,6 +629,82 @@ namespace
return install_action_options_to_value(tr1::static_pointer_cast<InstallAction>(*p)->options);
}
+ /*
+ * call-seq:
+ * UninstallActionOptions.new(no_config_protect) -> UninstallActionOptions
+ * UninstallActionOptions.new(Hash) -> UninstallActionOptions
+ *
+ * UninstallActionOptions.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
+ uninstall_action_options_new(int argc, VALUE *argv, VALUE self)
+ {
+ UninstallActionOptions * ptr(0);
+ try
+ {
+ bool v_no_config_protect;
+
+ if (1 == argc && rb_obj_is_kind_of(argv[0], rb_cHash))
+ {
+ if (Qnil == rb_hash_aref(argv[0], ID2SYM(rb_intern("no_config_protect"))))
+ rb_raise(rb_eArgError, "Missing Parameter: no_config_protect");
+ v_no_config_protect =
+ value_to_bool(rb_hash_aref(argv[0], ID2SYM(rb_intern("no_config_protect"))));
+ }
+ else if (1 == argc)
+ {
+ v_no_config_protect = value_to_bool(argv[0]);
+ }
+ else
+ {
+ rb_raise(rb_eArgError, "UninstallActionOptions expects one argument, but got %d",argc);
+ }
+
+ ptr = new UninstallActionOptions(UninstallActionOptions::create()
+ .no_config_protect(v_no_config_protect)
+ );
+
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<UninstallActionOptions>::free, ptr));
+ rb_obj_call_init(tdata, argc, argv);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
+ * call-seq:
+ * UninstallAction.new -> UninstallAction
+ */
+ VALUE
+ uninstall_action_new(VALUE self, VALUE opts)
+ {
+ const UninstallActionOptions opts_ptr(value_to_uninstall_action_options(opts));
+ tr1::shared_ptr<Action> * a(
+ new tr1::shared_ptr<Action>(new UninstallAction(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 -> UninstallActionOptions
+ *
+ * Our UninstallActionOptions.
+ */
+ VALUE
+ uninstall_action_options(VALUE self)
+ {
+ tr1::shared_ptr<Action> * p;
+ Data_Get_Struct(self, tr1::shared_ptr<Action>, p);
+ return uninstall_action_options_to_value(tr1::static_pointer_cast<UninstallAction>(*p)->options);
+ }
+
void do_register_action()
{
/*
@@ -630,6 +756,16 @@ namespace
rb_define_method(c_supports_install_action_test, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
/*
+ * Document-class: Paludis::SupportsUninstallActionTest
+ *
+ * Tests whether a Paludis::PackageID supports a Paludis::UninstallAction.
+ */
+ c_supports_uninstall_action_test = rb_define_class_under(paludis_module(), "SupportsUninstallActionTest", c_supports_action_test_base);
+ rb_define_singleton_method(c_supports_uninstall_action_test, "new",
+ RUBY_FUNC_CAST((&SupportsActionTestNew<UninstallAction>::supports_action_test_new)), 0);
+ rb_define_method(c_supports_uninstall_action_test, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
+
+ /*
* Document-class: Paludis::Action
*
* Base class for actions, used by Paludis::PackageID#perform_action.
@@ -744,12 +880,33 @@ namespace
/*
* Document-class: Paludis::InstallAction
*
- * An InstallAction is used by InstallTask to perform a build / install on a PackageID.
+ * An InstallAction is used by InstallTask to install a PackageID.
*/
c_install_action = rb_define_class_under(paludis_module(), "InstallAction", c_action);
rb_define_singleton_method(c_install_action, "new", RUBY_FUNC_CAST(&install_action_new), 1);
rb_define_method(c_install_action, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
rb_define_method(c_install_action, "options", RUBY_FUNC_CAST(&install_action_options), 0);
+
+ /*
+ * Document-class: Paludis::UninstallActionOptions
+ *
+ * Options for Paludis::UninstallAction.
+ */
+ c_uninstall_action_options = rb_define_class_under(paludis_module(), "UninstallActionOptions", rb_cObject);
+ rb_define_singleton_method(c_uninstall_action_options, "new", RUBY_FUNC_CAST(&uninstall_action_options_new), -1);
+ rb_define_method(c_uninstall_action_options, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
+ rb_define_method(c_uninstall_action_options, "no_config_protect?",
+ RUBY_FUNC_CAST((&BoolFetch<UninstallActionOptions, &UninstallActionOptions::no_config_protect>::fetch)), 0);
+
+ /*
+ * Document-class: Paludis::UninstallAction
+ *
+ * An UninstallAction is used by UninstallTask to uninstall a PackageID.
+ */
+ c_uninstall_action = rb_define_class_under(paludis_module(), "UninstallAction", c_action);
+ rb_define_singleton_method(c_uninstall_action, "new", RUBY_FUNC_CAST(&uninstall_action_new), 1);
+ rb_define_method(c_uninstall_action, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
+ rb_define_method(c_uninstall_action, "options", RUBY_FUNC_CAST(&uninstall_action_options), 0);
}
}
diff --git a/ruby/action_TEST.rb b/ruby/action_TEST.rb
index de00967..4947d89 100644
--- a/ruby/action_TEST.rb
+++ b/ruby/action_TEST.rb
@@ -23,6 +23,28 @@ require 'test/unit'
require 'Paludis'
module Paludis
+ module InstallActionModule
+ def env
+ @env or @env = EnvironmentMaker.instance.make_from_spec("")
+ end
+
+ def hash_args
+ InstallActionOptions.new(
+ {:no_config_protect => true, :debug_build => InstallActionDebugOption::Internal,
+ :checks => InstallActionChecksOption::Always, :destination => destination}
+ )
+ end
+
+ def long_args
+ InstallActionOptions.new(false, InstallActionDebugOption::Split,
+ InstallActionChecksOption::Default, destination)
+ end
+
+ def destination
+ @destination or @destination = FakeRepository.new(env, 'fake');
+ end
+ end
+
class TestCase_SupportsActionTestBase < Test::Unit::TestCase
def test_no_create
assert_raise NoMethodError do
@@ -52,6 +74,20 @@ module Paludis
end
end
+ class TestCase_SupportsInstallActionTest < Test::Unit::TestCase
+ def test_create
+ assert_kind_of SupportsInstallActionTest, SupportsInstallActionTest.new
+ assert_kind_of SupportsActionTestBase, SupportsInstallActionTest.new
+ end
+ end
+
+ class TestCase_SupportsUninstallActionTest < Test::Unit::TestCase
+ def test_create
+ assert_kind_of SupportsUninstallActionTest, SupportsUninstallActionTest.new
+ assert_kind_of SupportsActionTestBase, SupportsUninstallActionTest.new
+ end
+ end
+
class TestCase_Action < Test::Unit::TestCase
def test_no_create
assert_raise NoMethodError do
@@ -69,25 +105,7 @@ module Paludis
end
class TestCase_InstallActionOptions < Test::Unit::TestCase
- def env
- @env or @env = EnvironmentMaker.instance.make_from_spec("")
- end
-
- def hash_args
- InstallActionOptions.new(
- {:no_config_protect => true, :debug_build => InstallActionDebugOption::Internal,
- :checks => InstallActionChecksOption::Always, :destination => destination}
- )
- end
-
- def long_args
- InstallActionOptions.new(false, InstallActionDebugOption::Split,
- InstallActionChecksOption::Default, destination)
- end
-
- def destination
- @destination or @destination = FakeRepository.new(env, 'fake');
- end
+ include InstallActionModule
def test_create
assert_kind_of InstallActionOptions, long_args
@@ -111,6 +129,22 @@ module Paludis
end
end
+ class TestCase_UninstallActionOptions < Test::Unit::TestCase
+ def test_create
+ assert_kind_of UninstallActionOptions, UninstallActionOptions.new(true)
+ assert_kind_of UninstallActionOptions, UninstallActionOptions.new(
+ {:no_config_protect => false})
+ end
+
+ def test_methods
+ uao = UninstallActionOptions.new(true)
+ assert uao.no_config_protect?
+
+ uao = UninstallActionOptions.new({:no_config_protect => false})
+ assert !uao.no_config_protect?
+ end
+ end
+
class TestCase_FetchActionFailure < Test::Unit::TestCase
def test_create
assert_kind_of FetchActionFailure, FetchActionFailure.new('target_file', false, false, 'fic')
@@ -165,10 +199,12 @@ module Paludis
def test_options
a = FetchAction.new(FetchActionOptions.new(false, true))
+ assert_kind_of FetchActionOptions, a.options
assert !a.options.fetch_unneeded?
assert a.options.safe_resume?
a = FetchAction.new(FetchActionOptions.new({:safe_resume => false, :fetch_unneeded => true}))
+ assert_kind_of FetchActionOptions, a.options
assert a.options.fetch_unneeded?
assert !a.options.safe_resume?
end
@@ -199,6 +235,61 @@ module Paludis
end
end
end
+
+ class TestCase_InstallAction < Test::Unit::TestCase
+ include InstallActionModule
+
+ def test_create
+ assert_kind_of InstallAction, InstallAction.new(hash_args)
+ assert_kind_of Action, InstallAction.new(hash_args)
+
+ assert_kind_of InstallAction, InstallAction.new(long_args)
+ end
+
+ def test_bad_create
+ assert_raise TypeError do
+ InstallAction.new("foo")
+ end
+
+ assert_raise ArgumentError do
+ InstallAction.new(InstallActionOptions.new({:monkey => false}))
+ end
+ end
+
+ def test_options_hash_args
+ action = InstallAction.new(hash_args)
+ assert_kind_of InstallActionOptions, action.options
+ assert action.options.no_config_protect?
+ assert_equal InstallActionDebugOption::Internal, action.options.debug_build
+ assert_equal InstallActionChecksOption::Always, action.options.checks
+ assert_equal destination.name, action.options.destination.name
+ end
+ end
+
+ class TestCase_UninstallAction < Test::Unit::TestCase
+ def test_create
+ assert_kind_of UninstallAction, UninstallAction.new(UninstallActionOptions.new(true))
+ assert_kind_of Action, UninstallAction.new(UninstallActionOptions.new(true))
+
+ assert_kind_of UninstallAction, UninstallAction.new(UninstallActionOptions.new({:no_config_protect => false}))
+ end
+
+ def test_bad_create
+ assert_raise TypeError do
+ UninstallAction.new("foo")
+ end
+
+ assert_raise ArgumentError do
+ InstallAction.new(InstallActionOptions.new({:monkey => false}))
+ end
+ end
+
+ def test_options_hash_args
+ action = UninstallAction.new(UninstallActionOptions.new(false))
+ assert_kind_of UninstallActionOptions, action.options
+ assert !action.options.no_config_protect?
+ end
+ end
end
diff --git a/ruby/paludis_ruby.cc b/ruby/paludis_ruby.cc
index 44231dd..d328284 100644
--- a/ruby/paludis_ruby.cc
+++ b/ruby/paludis_ruby.cc
@@ -71,6 +71,7 @@ namespace
static VALUE c_info_action_error;
static VALUE c_config_action_error;
static VALUE c_install_action_error;
+ static VALUE c_uninstall_action_error;
static VALUE c_action_error;
static VALUE c_environment;
@@ -191,6 +192,8 @@ void paludis::ruby::exception_to_ruby_exception(const std::exception & ee)
rb_raise(c_config_action_error, dynamic_cast<const paludis::ConfigActionError *>(&ee)->message().c_str());
else if (0 != dynamic_cast<const paludis::InstallActionError *>(&ee))
rb_raise(c_install_action_error, dynamic_cast<const paludis::InstallActionError *>(&ee)->message().c_str());
+ else if (0 != dynamic_cast<const paludis::UninstallActionError *>(&ee))
+ rb_raise(c_uninstall_action_error, dynamic_cast<const paludis::UninstallActionError *>(&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());
@@ -388,6 +391,13 @@ void PALUDIS_VISIBLE paludis::ruby::init()
*/
c_install_action_error = rb_define_class_under(c_paludis_module, "InstallActionError", c_action_error);
+ /*
+ * Document-class: Paludis::UninstallActionError
+ *
+ * Thrown if a PackageID fails to perform a InstallAction.
+ */
+ c_uninstall_action_error = rb_define_class_under(c_paludis_module, "UninstallActionError", 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) + "."