aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-01-19 13:41:39 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-01-19 13:41:39 +0000
commit3ab920214db2acb12e67c5d9cb1a6d874ebce60e (patch)
tree65acd802c5d58199c987e90cfc126aafed941088
parentca1923b8bd6437bd9a488932d7af7334f32870fa (diff)
downloadpaludis-3ab920214db2acb12e67c5d9cb1a6d874ebce60e.tar.gz
paludis-3ab920214db2acb12e67c5d9cb1a6d874ebce60e.tar.xz
Expand PortageRepository in ruby.
-rw-r--r--ruby/repository.cc50
-rw-r--r--ruby/repository_TEST.rb33
2 files changed, 83 insertions, 0 deletions
diff --git a/ruby/repository.cc b/ruby/repository.cc
index a1c8e75..f398b36 100644
--- a/ruby/repository.cc
+++ b/ruby/repository.cc
@@ -597,6 +597,54 @@ namespace
}
/*
+ * call-seq:
+ * find_profile(profile_location) -> PortageRepositoryProfilesDescLine
+ *
+ * Fetches the named profile.
+ */
+ VALUE
+ portage_repository_find_profile(VALUE self, VALUE profile)
+ {
+ try
+ {
+ PortageRepository::ConstPointer * self_ptr;
+ Data_Get_Struct(self, PortageRepository::ConstPointer, self_ptr);
+
+ PortageRepository::ProfilesIterator p((*self_ptr)->find_profile(FSEntry(StringValuePtr(profile))));
+
+ if (p == (*self_ptr)->end_profiles())
+ return Qnil;
+
+ return portage_repository_profiles_desc_line_to_value(*p);
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
+ * call-seq:
+ * profile_variable(variable) -> String
+ *
+ * Fetches the named variable.
+ */
+ VALUE
+ portage_repository_profile_variable(VALUE self, VALUE var)
+ {
+ try
+ {
+ PortageRepository::ConstPointer * self_ptr;
+ Data_Get_Struct(self, PortageRepository::ConstPointer, self_ptr);
+ return rb_str_new2(((*self_ptr)->profile_variable(StringValuePtr(var))).c_str());
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
* Document-method: arch
*
* call-seq:
@@ -913,6 +961,8 @@ namespace
*/
c_portage_repository = rb_define_class_under(paludis_module(), "PortageRepository", c_repository);
rb_define_method(c_portage_repository, "profiles", RUBY_FUNC_CAST(&portage_repository_profiles), 0);
+ rb_define_method(c_portage_repository, "find_profile", RUBY_FUNC_CAST(&portage_repository_find_profile), 1);
+ rb_define_method(c_portage_repository, "profile_variable", RUBY_FUNC_CAST(&portage_repository_profile_variable), 1);
/*
* Document-class: Paludis::PortageRepositoryProfilesDescLine
diff --git a/ruby/repository_TEST.rb b/ruby/repository_TEST.rb
index c9c123e..17cb139 100644
--- a/ruby/repository_TEST.rb
+++ b/ruby/repository_TEST.rb
@@ -36,11 +36,44 @@ module Paludis
end
class TestCase_PortageRepository < Test::Unit::TestCase
+ def no_config_testrepo
+ NoConfigEnvironment.new Dir.getwd().to_s + "/repository_TEST_dir/testrepo"
+ end
+
def test_no_create
assert_raise NoMethodError do
p = PortageRepository.new
end
end
+
+ def test_responds
+ repo = no_config_testrepo.portage_repository
+ [:profile_variable, :profiles, :find_profile].each do |sym|
+ assert_respond_to repo, sym
+ end
+ end
+
+ def test_profiles
+ repo = no_config_testrepo.portage_repository
+ assert_kind_of Array, repo.profiles
+ end
+
+ def test_find_profile
+ repo = no_config_testrepo.portage_repository
+ assert_nothing_raised do
+ profile = repo.find_profile(Dir.getwd().to_s + '/repository_TEST_dir/testrepo/profiles/testprofile')
+ assert_kind_of PortageRepositoryProfilesDescLine, profile
+ profile = repo.find_profile('broken')
+ assert profile.nil?
+ end
+ end
+
+ def test_profile_variable
+ repo = no_config_testrepo.portage_repository
+ assert_nothing_raised do
+ assert_equal 'test', repo.profile_variable('ARCH')
+ end
+ end
end
module RepositoryTestCase