aboutsummaryrefslogtreecommitdiff
path: root/ruby/repository.cc
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-04 22:13:16 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-04 22:13:16 +0000
commitdb949a7a09484b44445cb832e48bc8f6d90fc636 (patch)
tree0f407091fbeb4d508e0cef582306fc581a1035b3 /ruby/repository.cc
parent63be8d5c13402c09badd6f7eec77bee3535e00d0 (diff)
downloadpaludis-db949a7a09484b44445cb832e48bc8f6d90fc636.tar.gz
paludis-db949a7a09484b44445cb832e48bc8f6d90fc636.tar.xz
(ruby) Allow fetching metadata from repositories with [].
Diffstat (limited to 'ruby/repository.cc')
-rw-r--r--ruby/repository.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/ruby/repository.cc b/ruby/repository.cc
index 4c9dc384c..8176cdc3f 100644
--- a/ruby/repository.cc
+++ b/ruby/repository.cc
@@ -853,6 +853,23 @@ namespace
/*
* call-seq:
+ * [String] -> MetadataKey or Nil
+ *
+ * The named metadata key.
+ */
+ VALUE
+ repository_subscript(VALUE self, VALUE raw_name)
+ {
+ tr1::shared_ptr<const Repository> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const Repository>, self_ptr);
+ Repository::MetadataConstIterator it((*self_ptr)->find_metadata(StringValuePtr(raw_name)));
+ if ((*self_ptr)->end_metadata() == it)
+ return Qnil;
+ return metadata_key_to_value(*it);
+ }
+
+ /*
+ * call-seq:
* each_metadata {|key| block } -> Nil
*
* Our metadata.
@@ -940,6 +957,7 @@ namespace
rb_define_method(c_repository, "check_qa", RUBY_FUNC_CAST(&repository_check_qa),5);
+ rb_define_method(c_repository, "[]", RUBY_FUNC_CAST(&repository_subscript), 1);
rb_define_method(c_repository, "each_metadata", RUBY_FUNC_CAST(&repository_each_metadata), 0);
rb_define_method(c_repository, "format_key",
RUBY_FUNC_CAST((&RepositoryKey<MetadataStringKey, &Repository::format_key>::fetch)), 0);