aboutsummaryrefslogtreecommitdiff
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
parent63be8d5c13402c09badd6f7eec77bee3535e00d0 (diff)
downloadpaludis-db949a7a09484b44445cb832e48bc8f6d90fc636.tar.gz
paludis-db949a7a09484b44445cb832e48bc8f6d90fc636.tar.xz
(ruby) Allow fetching metadata from repositories with [].
-rw-r--r--ruby/repository.cc18
-rw-r--r--ruby/repository_TEST.rb7
2 files changed, 25 insertions, 0 deletions
diff --git a/ruby/repository.cc b/ruby/repository.cc
index 4c9dc38..8176cdc 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);
diff --git a/ruby/repository_TEST.rb b/ruby/repository_TEST.rb
index 6062ffd..8e9ed01 100644
--- a/ruby/repository_TEST.rb
+++ b/ruby/repository_TEST.rb
@@ -605,6 +605,13 @@ module Paludis
def test_each_metadata
assert_respond_to repo, :each_metadata
end
+
+ def test_subscript
+ assert_respond_to repo, :[]
+ assert_kind_of MetadataStringKey, repo['format']
+ assert_equal 'ebuild', repo['format'].value
+ assert_nil repo['monkey']
+ end
end
end