aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2006-11-12 15:36:44 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2006-11-12 15:36:44 +0000
commitd98f52530e66c3c2db4f6a69e5d36b647bf452e8 (patch)
treeaa8ecbfb297915141a4d44d0f155645b2ba8d651
parent342df67f19661afb564d1688f0882c8411b82cc3 (diff)
downloadpaludis-d98f52530e66c3c2db4f6a69e5d36b647bf452e8.tar.gz
paludis-d98f52530e66c3c2db4f6a69e5d36b647bf452e8.tar.xz
Add environment->package_set to ruby bindings.
-rw-r--r--ruby/environment.cc17
-rw-r--r--ruby/environment_TEST.rb28
-rw-r--r--ruby/paludis_ruby.cc4
3 files changed, 49 insertions, 0 deletions
diff --git a/ruby/environment.cc b/ruby/environment.cc
index cb90956..b10d2a2 100644
--- a/ruby/environment.cc
+++ b/ruby/environment.cc
@@ -168,6 +168,22 @@ namespace
}
VALUE
+ environment_package_set(VALUE self, VALUE set_name)
+ {
+ EnvironmentData * env_data;
+ Data_Get_Struct(self, EnvironmentData, env_data);
+
+ try
+ {
+ return dep_atom_to_value(env_data->env_ptr->package_set(SetName(STR2CSTR(set_name))));
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
default_config_config_suffix(VALUE)
{
try
@@ -253,6 +269,7 @@ namespace
rb_define_method(c_environment, "accept_license", RUBY_FUNC_CAST(&environment_accept_license), -1);
rb_define_method(c_environment, "mask_reasons", RUBY_FUNC_CAST(&environment_mask_reasons), 1);
rb_define_method(c_environment, "package_database", RUBY_FUNC_CAST(&environment_package_database), 0);
+ rb_define_method(c_environment, "package_set", RUBY_FUNC_CAST(&environment_package_set), 1);
c_default_environment = rb_define_class_under(paludis_module(), "DefaultEnvironment", c_environment);
rb_define_singleton_method(c_default_environment, "new", RUBY_FUNC_CAST(&default_environment_new), 0);
diff --git a/ruby/environment_TEST.rb b/ruby/environment_TEST.rb
index f981830..9217146 100644
--- a/ruby/environment_TEST.rb
+++ b/ruby/environment_TEST.rb
@@ -255,5 +255,33 @@ module Paludis
assert_equal "testrepo", db.fetch_repository("testrepo").name
end
end
+
+ class TestCase_DefaultEnvironmentPackageSet < Test::Unit::TestCase
+ def test_package_set
+ assert_kind_of DepAtom, DefaultEnvironment.instance.package_set('everything')
+ end
+
+ def test_package_set_error
+ assert_raise SetNameError do
+ DefaultEnvironment.instance.package_set('broken*')
+ end
+ end
+ end
+
+ class TestCase_NoConfigEnvironmentPackageSet < Test::Unit::TestCase
+ def env
+ NoConfigEnvironment.new(Dir.getwd().to_s + "/environment_TEST_dir/testrepo")
+ end
+
+ def test_package_set
+ assert_kind_of DepAtom, DefaultEnvironment.instance.package_set('everything')
+ end
+
+ def test_package_set_error
+ assert_raise SetNameError do
+ env.package_set('broken*')
+ end
+ end
+ end
end
diff --git a/ruby/paludis_ruby.cc b/ruby/paludis_ruby.cc
index fc00272..285cd8d 100644
--- a/ruby/paludis_ruby.cc
+++ b/ruby/paludis_ruby.cc
@@ -42,6 +42,7 @@ namespace
{
static VALUE c_paludis_module;
static VALUE c_name_error;
+ static VALUE c_set_name_error;
static VALUE c_category_name_part_error;
static VALUE c_package_name_part_error;
static VALUE c_bad_version_spec_error;
@@ -103,6 +104,8 @@ void paludis::ruby::exception_to_ruby_exception(const std::exception & ee)
dynamic_cast<const paludis::InternalError *>(&ee)->message().c_str(), ee.what());
else if (0 != dynamic_cast<const paludis::BadVersionSpecError *>(&ee))
rb_raise(c_bad_version_spec_error, dynamic_cast<const paludis::BadVersionSpecError *>(&ee)->message().c_str());
+ else if (0 != dynamic_cast<const paludis::SetNameError *>(&ee))
+ rb_raise(c_set_name_error, dynamic_cast<const paludis::SetNameError *>(&ee)->message().c_str());
else if (0 != dynamic_cast<const paludis::PackageNamePartError *>(&ee))
rb_raise(c_package_name_part_error, dynamic_cast<const paludis::PackageNamePartError *>(&ee)->message().c_str());
else if (0 != dynamic_cast<const paludis::CategoryNamePartError *>(&ee))
@@ -171,6 +174,7 @@ extern "C"
{
c_paludis_module = rb_define_module("Paludis");
c_name_error = rb_define_class_under(c_paludis_module, "NameError", rb_eRuntimeError);
+ c_set_name_error = rb_define_class_under(c_paludis_module, "SetNameError", c_name_error);
c_category_name_part_error = rb_define_class_under(c_paludis_module, "CategoryNamePartError", c_name_error);
c_package_name_part_error = rb_define_class_under(c_paludis_module, "PackageNamePartError", c_name_error);
c_bad_version_spec_error = rb_define_class_under(c_paludis_module, "BadVersionSpecError", c_name_error);