aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-01-11 09:28:53 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-01-11 09:28:53 +0000
commitba2c674ae1f66cd9389eca1b73a74d72a0c8753f (patch)
tree577109ce6fe765a5b7b5ae2218d717f95a9ecd4b
parentadc0e653344878d3aae86c9dbd335a759f03c1ad (diff)
downloadpaludis-ba2c674ae1f66cd9389eca1b73a74d72a0c8753f.tar.gz
paludis-ba2c674ae1f66cd9389eca1b73a74d72a0c8753f.tar.xz
Add query_user_unmasks to ruby binding.
-rw-r--r--ruby/environment.cc47
-rw-r--r--ruby/environment_TEST.rb18
-rwxr-xr-xruby/environment_TEST_setup.sh4
3 files changed, 54 insertions, 15 deletions
diff --git a/ruby/environment.cc b/ruby/environment.cc
index 50d6b32..e9463bd 100644
--- a/ruby/environment.cc
+++ b/ruby/environment.cc
@@ -153,27 +153,41 @@ namespace
}
/*
+ * Document-method: query_user_masks
+ *
* call-seq:
- * query_user_masks(package_database_entry)
+ * query_user_masks(package_database_entry) -> true or false
*
* Are there any user masks on a PackageDatabaseEntry?
*/
- VALUE
- environment_query_user_masks(VALUE self, VALUE pde_value)
+ /*
+ * Document-method: query_user_unmasks
+ *
+ * call-seq:
+ * query_user_unmasks(package_database_entry) -> true or false
+ *
+ * Are there any user unmasks on a PackageDatabaseEntry?
+ */
+ template <bool (Environment::* m_) (const PackageDatabaseEntry &) const>
+ struct EnvBoolStruct
{
- EnvironmentData * env_data;
- Data_Get_Struct(self, EnvironmentData, env_data);
-
- PackageDatabaseEntry pde = value_to_package_database_entry(pde_value);
- try
- {
- return env_data->env_ptr->query_user_masks(pde) ? Qtrue : Qfalse;
- }
- catch (const std::exception & e)
+ static VALUE
+ fetch(VALUE self, VALUE pde_value)
{
- exception_to_ruby_exception(e);
+ EnvironmentData * env_data;
+ Data_Get_Struct(self, EnvironmentData, env_data);
+ PackageDatabaseEntry pde = value_to_package_database_entry(pde_value);
+ try
+ {
+ return ((env_data->env_ptr)->*m_)(pde) ? Qtrue : Qfalse;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+
}
- }
+ };
/*
* Fetch our PackageDatabase.
@@ -376,7 +390,10 @@ namespace
rb_define_method(c_environment, "accept_keyword", RUBY_FUNC_CAST(&environment_accept_keyword), -1);
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, "query_user_masks", RUBY_FUNC_CAST(&environment_query_user_masks), 1);
+ rb_define_method(c_environment, "query_user_masks",
+ RUBY_FUNC_CAST((&EnvBoolStruct<&Environment::query_user_masks>::fetch)), 1);
+ rb_define_method(c_environment, "query_user_unmasks",
+ RUBY_FUNC_CAST((&EnvBoolStruct<&Environment::query_user_unmasks>::fetch)), 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);
diff --git a/ruby/environment_TEST.rb b/ruby/environment_TEST.rb
index de9b996..acbc28a 100644
--- a/ruby/environment_TEST.rb
+++ b/ruby/environment_TEST.rb
@@ -265,6 +265,14 @@ module Paludis
assert env.query_user_masks(p3)
end
+ def test_query_user_unmasks
+ p2 = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("2.0"), "testrepo")
+ p3 = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("3.0"), "testrepo")
+
+ assert env.query_user_unmasks(p2)
+ assert ! env.query_user_unmasks(p3)
+ end
+
def test_query_user_masks_bad
p = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("2.0"), "testrepo")
assert_raise ArgumentError do
@@ -274,6 +282,16 @@ module Paludis
env.query_user_masks(123)
end
end
+
+ def test_query_user_unmasks_bad
+ p = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("2.0"), "testrepo")
+ assert_raise ArgumentError do
+ env.query_user_unmasks(p, p)
+ end
+ assert_raise TypeError do
+ env.query_user_unmasks(123)
+ end
+ end
end
class TestCase_DefaultEnvironmentPackageDatabase < Test::Unit::TestCase
diff --git a/ruby/environment_TEST_setup.sh b/ruby/environment_TEST_setup.sh
index e7ac099..8538b5d 100755
--- a/ruby/environment_TEST_setup.sh
+++ b/ruby/environment_TEST_setup.sh
@@ -28,6 +28,10 @@ cat <<END > home/.paludis/package_mask.conf
=foo/bar-3*
END
+cat <<END > home/.paludis/package_unmask.conf
+=foo/bar-2*
+END
+
cat <<END > home/.paludis/licenses.conf
* *
END