aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-01-10 11:43:12 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-01-10 11:43:12 +0000
commit179fadb0fa8406e089c4df478c017acdaf50edc4 (patch)
treec9cf3f852fef505746381998c47175ea72e159fe
parent6148bd0ac128ebc07c7d37a097b316cc3a41e410 (diff)
downloadpaludis-179fadb0fa8406e089c4df478c017acdaf50edc4.tar.gz
paludis-179fadb0fa8406e089c4df478c017acdaf50edc4.tar.xz
Ruby binding improvements.
-rw-r--r--ruby/demos/find_unmanaged_files.rb4
-rw-r--r--ruby/package_database.cc11
-rw-r--r--ruby/package_database_TEST.rb2
-rw-r--r--ruby/repository.cc24
-rw-r--r--ruby/repository_TEST.rb14
5 files changed, 51 insertions, 4 deletions
diff --git a/ruby/demos/find_unmanaged_files.rb b/ruby/demos/find_unmanaged_files.rb
index 4ef3e42..3b39758 100644
--- a/ruby/demos/find_unmanaged_files.rb
+++ b/ruby/demos/find_unmanaged_files.rb
@@ -95,8 +95,8 @@ Find.find(*files) {|file| in_fs << file}
Paludis::DefaultConfig::config_suffix = config_suffix
db = DefaultEnvironment.instance.package_database
-db.repositories.each do |repo|
- next unless repo.installed_interface
+db.repositories do |repo|
+ next unless repo.format == 'vdb'
in_fs-= get_contents(repo, files)
end
diff --git a/ruby/package_database.cc b/ruby/package_database.cc
index ae8645a..1deb8fd 100644
--- a/ruby/package_database.cc
+++ b/ruby/package_database.cc
@@ -127,8 +127,10 @@ namespace
/*
* call-seq:
* repositories -> Array
+ * repositories {|repository| block } -> Nil
*
- * Returns an array of Repository
+ * Returns all the repositories in the package database, either as an Array, or as
+ * the parameters to a block.
*/
VALUE
package_database_repositories(VALUE self)
@@ -138,6 +140,13 @@ namespace
PackageDatabase::Pointer * self_ptr;
Data_Get_Struct(self, PackageDatabase::Pointer, self_ptr);
+ if (rb_block_given_p())
+ {
+ for (PackageDatabase::RepositoryIterator r((*self_ptr)->begin_repositories()),
+ r_end((*self_ptr)->end_repositories()) ; r != r_end ; ++r)
+ rb_yield(repository_to_value(*r));
+ return Qnil;
+ }
VALUE result(rb_ary_new());
for (PackageDatabase::RepositoryIterator r((*self_ptr)->begin_repositories()),
r_end((*self_ptr)->end_repositories()) ; r != r_end ; ++r)
diff --git a/ruby/package_database_TEST.rb b/ruby/package_database_TEST.rb
index 9e1cfd3..907da87 100644
--- a/ruby/package_database_TEST.rb
+++ b/ruby/package_database_TEST.rb
@@ -129,6 +129,8 @@ module Paludis
repo.name == "foorepo"
end
assert a.empty?
+
+ assert_equal nil, db.repositories {|repo| assert_kind_of Repository, repo}
end
def test_fetch_repository
diff --git a/ruby/repository.cc b/ruby/repository.cc
index 570dd90..925f06c 100644
--- a/ruby/repository.cc
+++ b/ruby/repository.cc
@@ -39,7 +39,7 @@ namespace
/*
* call-seq:
- * name
+ * name -> String
*
* Returns our name.
*/
@@ -60,6 +60,27 @@ namespace
/*
* call-seq:
+ * format -> String
+ *
+ * Returns our format.
+ */
+ VALUE
+ repository_format(VALUE self)
+ {
+ try
+ {
+ Repository::ConstPointer * self_ptr;
+ Data_Get_Struct(self, Repository::ConstPointer, self_ptr);
+ return rb_str_new2(stringify((*self_ptr)->format()).c_str());
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
+ * call-seq:
* has_category_named?(category_name) -> true or false
*
* Do we have a category with the given name?
@@ -812,6 +833,7 @@ namespace
c_repository = rb_define_class_under(paludis_module(), "Repository", rb_cObject);
rb_funcall(c_repository, rb_intern("private_class_method"), 1, rb_str_new2("new"));
rb_define_method(c_repository, "name", RUBY_FUNC_CAST(&repository_name), 0);
+ rb_define_method(c_repository, "format", RUBY_FUNC_CAST(&repository_format), 0);
rb_define_method(c_repository, "has_category_named?", RUBY_FUNC_CAST(&repository_has_category_named), 1);
rb_define_method(c_repository, "has_package_named?", RUBY_FUNC_CAST(&repository_has_package_named), 1);
diff --git a/ruby/repository_TEST.rb b/ruby/repository_TEST.rb
index 410dc50..c9c123e 100644
--- a/ruby/repository_TEST.rb
+++ b/ruby/repository_TEST.rb
@@ -61,6 +61,20 @@ module Paludis
end
end
+ class TestCase_Repository < Test::Unit::TestCase
+ include RepositoryTestCase
+
+ def test_name
+ assert_equal "installed", installed_repo.name
+ assert_equal "testrepo", repo.name
+ end
+
+ def test_format
+ assert_equal "vdb", installed_repo.format
+ assert_equal "ebuild", repo.format
+ end
+ end
+
class TestCase_RepositoryHasVersion < Test::Unit::TestCase
include RepositoryTestCase