aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2008-01-22 09:33:59 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2008-01-22 09:33:59 +0000
commit3acdbde6298e2f5fb9be182fbe1882d8fa5ae1a6 (patch)
tree02de1286e03353475b136e01deb0b18b8c6202cf
parent1463d109f49cc0a9c7e3a3aaf2217c5e525956ba (diff)
downloadpaludis-3acdbde6298e2f5fb9be182fbe1882d8fa5ae1a6.tar.gz
paludis-3acdbde6298e2f5fb9be182fbe1882d8fa5ae1a6.tar.xz
(ruby) Add Repository.get_environment_variable.
-rw-r--r--ruby/repository.cc21
-rw-r--r--ruby/repository_TEST.rb16
-rwxr-xr-xruby/repository_TEST_setup.sh1
3 files changed, 36 insertions, 2 deletions
diff --git a/ruby/repository.cc b/ruby/repository.cc
index f4f7e41..83f5a13 100644
--- a/ruby/repository.cc
+++ b/ruby/repository.cc
@@ -2,7 +2,7 @@
/*
* Copyright (c) 2006, 2007 Ciaran McCreesh
- * Copyright (c) 2006, 2007 Richard Brown
+ * Copyright (c) 2006, 2007, 2008 Richard Brown
* Copyright (c) 2007 David Leverton
*
* This file is part of the Paludis package manager. Paludis is free software;
@@ -884,6 +884,24 @@ namespace
}
};
+ /*
+ * call-seq:
+ * get_environment_variable(package_id, environment_variable) -> String
+ *
+ * Query an environment variable.
+ */
+ VALUE
+ repository_get_environment_variable(VALUE self, VALUE pid, VALUE ev)
+ {
+ tr1::shared_ptr<Repository> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<Repository>, self_ptr);
+ if ((*self_ptr)->environment_variable_interface)
+ return rb_str_new2((*self_ptr)->environment_variable_interface->get_environment_variable(value_to_package_id(pid),StringValuePtr(ev)).c_str());
+
+ return Qnil;
+
+ }
+
void do_register_repository()
{
/*
@@ -948,6 +966,7 @@ namespace
RUBY_FUNC_CAST((&RepositoryKey<MetadataStringKey, &Repository::format_key>::fetch)), 0);
rb_define_method(c_repository, "installed_root_key",
RUBY_FUNC_CAST((&RepositoryKey<MetadataFSEntryKey, &Repository::installed_root_key>::fetch)), 0);
+ rb_define_method(c_repository, "get_environment_variable", RUBY_FUNC_CAST(&repository_get_environment_variable),2);
/*
* Document-class: Paludis::ProfilesDescLine
diff --git a/ruby/repository_TEST.rb b/ruby/repository_TEST.rb
index 8e9ed01..04060bd 100644
--- a/ruby/repository_TEST.rb
+++ b/ruby/repository_TEST.rb
@@ -3,7 +3,7 @@
#
# Copyright (c) 2006, 2007 Ciaran McCreesh
-# Copyright (c) 2006, 2007 Richard Brown
+# Copyright (c) 2006, 2007, 2008 Richard Brown
#
# This file is part of the Paludis package manager. Paludis is free software;
# you can redistribute it and/or modify it under the terms of the GNU General
@@ -613,5 +613,19 @@ module Paludis
assert_nil repo['monkey']
end
end
+
+ class TestCase_RepositoryEnvironmentVariables < Test::Unit::TestCase
+ include RepositoryTestCase
+
+ def text_repository_environment_interface
+ assert_not_nil repo.environment_variable_interface
+ end
+
+ def test_get_environment_variable
+ pid = db.query(Query::Matches.new(Paludis::parse_user_package_dep_spec('=foo/bar-1.0', [])), QueryOrder::BestVersionOnly).first;
+ assert_equal "hello", repo.get_environment_variable(pid, "TEST_ENV_VAR")
+ assert_equal "", repo.get_environment_variable(pid, "TEST_UNSET_ENV_VAR")
+ end
+ end
end
diff --git a/ruby/repository_TEST_setup.sh b/ruby/repository_TEST_setup.sh
index c006420..d16e4ef 100755
--- a/ruby/repository_TEST_setup.sh
+++ b/ruby/repository_TEST_setup.sh
@@ -104,6 +104,7 @@ SLOT="0"
IUSE="test1"
LICENSE="GPL-2"
KEYWORDS="test"
+TEST_ENV_VAR="hello"
END
cat <<"END" > foo/bar/bar-2.0.ebuild || exit 1