aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-07-02 16:15:36 +0100
committerAvatar David Leverton <levertond@googlemail.com> 2008-07-25 21:37:18 +0100
commit67b907b14fcb8751d3d1ac4551b760f91560e110 (patch)
tree17565fd4bcec2a23484540ae728da5a9222aed96
parent78d31e69f521798ef9f82027e0f5ca0d33ee7d40 (diff)
downloadpaludis-67b907b14fcb8751d3d1ac4551b760f91560e110.tar.gz
paludis-67b907b14fcb8751d3d1ac4551b760f91560e110.tar.xz
(ruby) Add bindings to the new specific Environment MetadataKey methods.
-rw-r--r--ruby/environment.cc16
-rw-r--r--ruby/environment_TEST.rb32
2 files changed, 48 insertions, 0 deletions
diff --git a/ruby/environment.cc b/ruby/environment.cc
index e13e332..96fc8c1 100644
--- a/ruby/environment.cc
+++ b/ruby/environment.cc
@@ -255,6 +255,18 @@ namespace
}
+ template <typename T_, const std::tr1::shared_ptr<const T_> (Environment::* m_) () const>
+ struct EnvironmentKey
+ {
+ static VALUE
+ fetch(VALUE self)
+ {
+ std::tr1::shared_ptr<Environment> * self_ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<Environment>, self_ptr);
+ return (((**self_ptr).*m_)()) ? metadata_key_to_value(((**self_ptr).*m_)()) : Qnil;
+ }
+ };
+
std::tr1::shared_ptr<PaludisEnvironment>
value_to_paludis_environment(VALUE v)
{
@@ -558,6 +570,10 @@ namespace
rb_define_method(c_environment, "accept_keywords", RUBY_FUNC_CAST(&environment_accept_keywords), 2);
rb_define_method(c_environment, "mirrors", RUBY_FUNC_CAST(&environment_mirrors), 1);
rb_define_method(c_environment, "[]", RUBY_FUNC_CAST(&environment_square_brackets), 1);
+ rb_define_method(c_environment, "format_key",
+ RUBY_FUNC_CAST((&EnvironmentKey<MetadataValueKey<std::string> , &Environment::format_key>::fetch)), 0);
+ rb_define_method(c_environment, "config_location_key",
+ RUBY_FUNC_CAST((&EnvironmentKey<MetadataValueKey<FSEntry>, &Environment::config_location_key>::fetch)), 0);
/*
* Document-class: Paludis::PaludisEnvironment
diff --git a/ruby/environment_TEST.rb b/ruby/environment_TEST.rb
index 70ca56b..09a76eb 100644
--- a/ruby/environment_TEST.rb
+++ b/ruby/environment_TEST.rb
@@ -503,5 +503,37 @@ module Paludis
assert a.empty?
end
end
+
+ class TestCase_EnvironmentMetadataKeys < Test::Unit::TestCase
+ def env
+ @env or @env = EnvironmentMaker.instance.make_from_spec("")
+ end
+
+ def ncenv
+ @ncenv or @ncenv = NoConfigEnvironment.new(Dir.getwd().to_s + "/environment_TEST_dir/testrepo")
+ end
+
+ def test_format_key
+ assert_respond_to env, :format_key
+ assert_not_nil env.format_key
+ assert_kind_of MetadataStringKey, env.format_key
+ assert_equal 'paludis', env.format_key.value
+
+ assert_respond_to ncenv, :format_key
+ assert_not_nil ncenv.format_key
+ assert_kind_of MetadataStringKey, ncenv.format_key
+ assert_equal 'no_config', ncenv.format_key.value
+ end
+
+ def test_config_location_key
+ assert_respond_to env, :config_location_key
+ assert_not_nil env.config_location_key
+ assert_kind_of MetadataFSEntryKey, env.config_location_key
+ assert_equal Dir.getwd().to_s + "/environment_TEST_dir/home/.paludis", env.config_location_key.value
+
+ assert_respond_to ncenv, :config_location_key
+ assert_nil ncenv.config_location_key
+ end
+ end
end