aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2006-12-10 02:35:07 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2006-12-10 02:35:07 +0000
commiteb29f47953dffd5fb4f877fe16d786365f4663a6 (patch)
tree9e9bb692e09034a470b2ad9c430d172b2da48825
parenta8a56bd2aff1012d3f7471482162dc8c2d655125 (diff)
downloadpaludis-eb29f47953dffd5fb4f877fe16d786365f4663a6.tar.gz
paludis-eb29f47953dffd5fb4f877fe16d786365f4663a6.tar.xz
Add category_names_containing_package to ruby binding.
-rw-r--r--ruby/repository.cc23
-rw-r--r--ruby/repository_TEST.rb12
2 files changed, 34 insertions, 1 deletions
diff --git a/ruby/repository.cc b/ruby/repository.cc
index c8ef766..8cea3cb 100644
--- a/ruby/repository.cc
+++ b/ruby/repository.cc
@@ -114,6 +114,27 @@ namespace
}
VALUE
+ repository_category_names_containing_package(VALUE self, VALUE pkg)
+ {
+ try
+ {
+ Repository::ConstPointer * self_ptr;
+ Data_Get_Struct(self, Repository::ConstPointer, self_ptr);
+ PackageNamePart package(StringValuePtr(pkg));
+
+ VALUE result(rb_ary_new());
+ CategoryNamePartCollection::ConstPointer c((*self_ptr)->category_names_containing_package(package));
+ for (CategoryNamePartCollection::Iterator i(c->begin()), i_end(c->end()) ; i != i_end ; ++i)
+ rb_ary_push(result, rb_str_new2(stringify(*i).c_str()));
+ return result;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
repository_package_names(VALUE self, VALUE cat)
{
try
@@ -300,6 +321,8 @@ namespace
rb_define_method(c_repository, "has_version?", RUBY_FUNC_CAST(&repository_has_version), 2);
rb_define_method(c_repository, "category_names", RUBY_FUNC_CAST(&repository_category_names), 0);
+ rb_define_method(c_repository, "category_names_containing_package",
+ RUBY_FUNC_CAST(&repository_category_names_containing_package), 1);
rb_define_method(c_repository, "package_names", RUBY_FUNC_CAST(&repository_package_names), 1);
rb_define_method(c_repository, "version_specs", RUBY_FUNC_CAST(&repository_version_specs), 1);
diff --git a/ruby/repository_TEST.rb b/ruby/repository_TEST.rb
index b3c1025..efe4294 100644
--- a/ruby/repository_TEST.rb
+++ b/ruby/repository_TEST.rb
@@ -111,7 +111,17 @@ module Paludis
def test_category_names
a = repo.category_names
assert_equal 1, a.length
- assert_equal "foo", a[0]
+ assert_equal "foo", a.first
+ end
+ end
+
+ class TestCase_RepositoryCategoryNamesContainingPackage < Test::Unit::TestCase
+ include RepositoryTestCase
+
+ def test_category_names_containing_package
+ a = repo.category_names_containing_package('bar')
+ assert_equal 1, a.length
+ assert_equal "foo", a.first
end
end