aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2006-12-24 20:24:23 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2006-12-24 20:24:23 +0000
commit3cf5182bc49324637d6581ebdc20aec78bd7a8b7 (patch)
tree99395a86f1fc18ba50647f77c4edd9a4f6d41da0
parentdb58f51c369f798361ed5e3469cb8cb190c81e63 (diff)
downloadpaludis-3cf5182bc49324637d6581ebdc20aec78bd7a8b7.tar.gz
paludis-3cf5182bc49324637d6581ebdc20aec78bd7a8b7.tar.xz
Add describe_use_flag to ruby.
-rw-r--r--ruby/repository.cc48
-rw-r--r--ruby/repository_TEST.rb19
-rwxr-xr-xruby/repository_TEST_setup.sh13
3 files changed, 78 insertions, 2 deletions
diff --git a/ruby/repository.cc b/ruby/repository.cc
index 3689883..3e51235 100644
--- a/ruby/repository.cc
+++ b/ruby/repository.cc
@@ -720,6 +720,52 @@ namespace
}
};
+ /*
+ * call-seq:
+ * describe_use_flag(flag_name) -> String or Nil
+ * describe_use_flag(flag_name, package_database_entry) -> String or Nil
+ *
+ * Returns the description for a use flag name, or nil if the repository does not include
+ * the use_flag_interface.
+ */
+ VALUE
+ repository_describe_use_flag(int argc, VALUE * argv, VALUE self)
+ {
+ try
+ {
+ Repository::ConstPointer * self_ptr;
+ Data_Get_Struct(self, Repository::ConstPointer, self_ptr);
+ if ((*self_ptr)->use_interface) {
+ if (1 == argc || 2 ==argc)
+ {
+ UseFlagName ufn = UseFlagName(StringValuePtr(argv[0]));
+ PackageDatabaseEntry * pde(0);
+ if (2 == argc)
+ {
+ PackageDatabaseEntry pde2 = value_to_package_database_entry(argv[1]);
+ pde = &pde2;
+ }
+
+ return rb_str_new2(((*self_ptr)->use_interface->describe_use_flag(ufn, pde).c_str()));
+
+ }
+ else
+ {
+ rb_raise(rb_eArgError, "describe_use_flag expects one or two arguments, but got %d", argc);
+ }
+ }
+ else
+ {
+ return Qnil;
+ }
+
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
void do_register_repository()
{
/*
@@ -781,6 +827,8 @@ namespace
rb_define_method(c_repository, "query_repository_masks", RUBY_FUNC_CAST(&QueryMasks<&RepositoryMaskInterface::query_repository_masks>::query), 2);
rb_define_method(c_repository, "query_profile_masks", RUBY_FUNC_CAST(&QueryMasks<&RepositoryMaskInterface::query_profile_masks>::query), 2);
+ rb_define_method(c_repository, "describe_use_flag", RUBY_FUNC_CAST(&repository_describe_use_flag),-1);
+
/*
* Document-class: Paludis::RepositoryInfo
*
diff --git a/ruby/repository_TEST.rb b/ruby/repository_TEST.rb
index 8d94a2c..0a3ecf1 100644
--- a/ruby/repository_TEST.rb
+++ b/ruby/repository_TEST.rb
@@ -451,5 +451,24 @@ module Paludis
assert_equal 'stable', profiles.first.status
end
end
+
+ class TestCase_RepositoryDescribeUseFlag < Test::Unit::TestCase
+ include RepositoryTestCase
+
+ def test_responds
+ assert_respond_to repo, :describe_use_flag
+ end
+
+ def test_one_arg
+ assert_kind_of String, repo.describe_use_flag('test1')
+ assert_equal 'A test use flag', repo.describe_use_flag('test1')
+ end
+
+ def test_two_args
+ pde = PackageDatabaseEntry.new('foo/bar','2.0','testrepo')
+ assert_kind_of String, repo.describe_use_flag('test1', pde)
+ assert_equal 'A test local use flag', repo.describe_use_flag('test2', pde)
+ end
+ end
end
diff --git a/ruby/repository_TEST_setup.sh b/ruby/repository_TEST_setup.sh
index a8e1275..88b4dcd 100755
--- a/ruby/repository_TEST_setup.sh
+++ b/ruby/repository_TEST_setup.sh
@@ -84,12 +84,21 @@ cat <<END > profiles/testprofile/package.use.force || exit 1
foo/bar test7
END
+cat <<END > profiles/use.desc || exit 1
+test1 - A test use flag
+END
+
+cat <<END > profiles/use.local.desc || exit 1
+foo/bar:test2 - A test local use flag
+END
+
+
cat <<"END" > foo/bar/bar-1.0.ebuild || exit 1
DESCRIPTION="Test package"
HOMEPAGE="http://paludis.berlios.de/"
SRC_URI=""
SLOT="0"
-IUSE=""
+IUSE="test1"
LICENSE="GPL-2"
KEYWORDS="test"
END
@@ -99,7 +108,7 @@ DESCRIPTION="Test package"
HOMEPAGE="http://paludis.berlios.de/"
SRC_URI=""
SLOT="0"
-IUSE=""
+IUSE="test2"
LICENSE="GPL-2"
KEYWORDS="~test"
END