aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2010-11-25 00:00:00 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2010-11-25 00:00:00 +0000
commit1329c8ecedf04c1bc7523b4a7bd3dea8b2f4e426 (patch)
tree6f8845ed33c2086b75ffeea566c76ad00562450a
parent82a496863bca5087cdf96a560788bc87d51f2b51 (diff)
downloadpaludis-1329c8ecedf04c1bc7523b4a7bd3dea8b2f4e426.tar.gz
paludis-1329c8ecedf04c1bc7523b4a7bd3dea8b2f4e426.tar.xz
Support MetadataStringStringMapKey.value
-rw-r--r--ruby/metadata_key.cc30
-rw-r--r--ruby/repository_TEST.rb9
-rwxr-xr-xruby/repository_TEST_setup.sh1
3 files changed, 40 insertions, 0 deletions
diff --git a/ruby/metadata_key.cc b/ruby/metadata_key.cc
index c956928..ed80d36 100644
--- a/ruby/metadata_key.cc
+++ b/ruby/metadata_key.cc
@@ -482,6 +482,35 @@ namespace
/*
* call-seq:
+ * value -> Hash
+ *
+ * Our Value.
+ * */
+ template <typename T_>
+ struct MapValue
+ {
+ static VALUE
+ fetch(VALUE self)
+ {
+ try
+ {
+ std::shared_ptr<const MetadataKey> * self_ptr;
+ Data_Get_Struct(self, std::shared_ptr<const MetadataKey>, self_ptr);
+ std::shared_ptr<const T_> c = std::static_pointer_cast<const MetadataCollectionKey<T_> >(*self_ptr)->value();
+ VALUE result (rb_hash_new());
+ for (typename T_::ConstIterator i(c->begin()), i_end(c->end()) ; i != i_end ; ++i)
+ rb_hash_aset(result, rb_str_new2(stringify(i->first).c_str()), rb_str_new2(stringify(i->second).c_str()));
+ return result;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+ };
+
+ /*
+ * call-seq:
* value -> Array
*
* Our Value.
@@ -784,6 +813,7 @@ namespace
* Metadata class for String to String maps.
*/
c_metadata_string_string_map_key = rb_define_class_under(paludis_module(), "MetadataStringStringMapKey", c_metadata_key);
+ rb_define_method(c_metadata_string_string_map_key, "value", RUBY_FUNC_CAST((&MapValue<Map<std::string, std::string> >::fetch)), 0);
/*
* Document-class: Paludis::MetadataStringSequenceKey
diff --git a/ruby/repository_TEST.rb b/ruby/repository_TEST.rb
index 7a5b788..aec9b21 100644
--- a/ruby/repository_TEST.rb
+++ b/ruby/repository_TEST.rb
@@ -400,6 +400,15 @@ module Paludis
assert_equal 'e', repo['format'].value
assert_nil repo['monkey']
end
+
+ def test_sync
+ assert_kind_of MetadataStringStringMapKey, repo['sync']
+ assert_kind_of Hash, repo['sync'].value
+ assert_equal 3, repo['sync'].value.size
+ assert_equal 'normalsync', repo['sync'].value['']
+ assert_equal 'foosync', repo['sync'].value['foo']
+ assert_equal 'barsync', repo['sync'].value['bar']
+ end
end
end
diff --git a/ruby/repository_TEST_setup.sh b/ruby/repository_TEST_setup.sh
index ae218a2..ffca5aa 100755
--- a/ruby/repository_TEST_setup.sh
+++ b/ruby/repository_TEST_setup.sh
@@ -13,6 +13,7 @@ names_cache = /var/empty
cache = /var/empty
profiles = \${location}/profiles/testprofile
builddir = `pwd`
+sync = normalsync foo: foosync bar: barsync
END
cat <<END > home/.paludis/repositories/installed.conf