aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2006-12-06 08:04:13 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2006-12-06 08:04:13 +0000
commit2c31326b6322b1c0e66fc93e161dfa4e692baa49 (patch)
tree80ac8d965a0ca991598f33584b9a89aa0e55f097
parent688a2ab17e674081307977b5f39e4eeda0236cb4 (diff)
downloadpaludis-2c31326b6322b1c0e66fc93e161dfa4e692baa49.tar.gz
paludis-2c31326b6322b1c0e66fc93e161dfa4e692baa49.tar.xz
Add ruby binding for VersionMetadataOrigins.
-rw-r--r--ruby/version_metadata.cc25
-rw-r--r--ruby/version_metadata_TEST.rb17
-rwxr-xr-xruby/version_metadata_TEST_setup.sh9
3 files changed, 51 insertions, 0 deletions
diff --git a/ruby/version_metadata.cc b/ruby/version_metadata.cc
index f1da8b2..27596fb 100644
--- a/ruby/version_metadata.cc
+++ b/ruby/version_metadata.cc
@@ -19,6 +19,7 @@
#include <paludis_ruby.hh>
#include <paludis/version_metadata.hh>
+#include <paludis/package_database_entry.hh>
#include <paludis/util/stringify.hh>
#include <ruby.h>
@@ -119,6 +120,25 @@ namespace
}
};
+ template <CountedPtr<PackageDatabaseEntry, count_policy::ExternalCountTag> VersionMetadataOrigins::* m_>
+ struct VMOrigins
+ {
+ static VALUE
+ fetch(VALUE self)
+ {
+ VersionMetadata::ConstPointer * self_ptr;
+ Data_Get_Struct(self, VersionMetadata::ConstPointer, self_ptr);
+ if ((&(*self_ptr)->origins)->*m_)
+ {
+ return package_database_entry_to_value(*((&(*self_ptr)->origins)->*m_));
+ }
+ else
+ {
+ return Qnil;
+ }
+ }
+ };
+
void do_register_version_metadata()
{
c_version_metadata = rb_define_class_under(paludis_module(), "VersionMetadata", rb_cObject);
@@ -166,6 +186,11 @@ namespace
&VersionMetadataDeps::run_depend_string>::fetch)), 0);
rb_define_method(c_version_metadata, "post_depend_string", RUBY_FUNC_CAST((&DependValueString<
&VersionMetadataDeps::post_depend_string>::fetch)), 0);
+
+ rb_define_method(c_version_metadata, "origin_source", RUBY_FUNC_CAST((&VMOrigins<
+ &VersionMetadataOrigins::source>::fetch)), 0);
+ rb_define_method(c_version_metadata, "origin_binary", RUBY_FUNC_CAST((&VMOrigins<
+ &VersionMetadataOrigins::binary>::fetch)), 0);
}
}
diff --git a/ruby/version_metadata_TEST.rb b/ruby/version_metadata_TEST.rb
index c11bc19..0a82265 100644
--- a/ruby/version_metadata_TEST.rb
+++ b/ruby/version_metadata_TEST.rb
@@ -38,10 +38,21 @@ module Paludis
@env
end
+ def env_vdb
+ unless @env_vdb
+ @env_vdb = NoConfigEnvironment.new("version_metadata_TEST_dir/installed/")
+ end
+ @env_vdb
+ end
+
def vmd version
env.package_database.fetch_repository("testrepo").version_metadata("foo/bar", version)
end
+ def vmd_vdb package, version
+ env_vdb.package_database.fetch_repository("installed").version_metadata(package, version)
+ end
+
def test_license
assert_kind_of DepAtom, vmd("1.0").license
end
@@ -82,6 +93,12 @@ module Paludis
assert_equal "", vmd("1.0").run_depend_string.gsub(/\s/, "")
assert_equal "", vmd("1.0").post_depend_string.gsub(/\s/, "")
end
+
+ def test_origin_source
+ assert_equal PackageDatabaseEntry.new('cat-one/pkg-one', '1', 'origin_test'),
+ vmd_vdb('cat-one/pkg-one','1').origin_source
+ assert_nil vmd_vdb('cat-one/pkg-two','1').origin_source
+ end
end
end
diff --git a/ruby/version_metadata_TEST_setup.sh b/ruby/version_metadata_TEST_setup.sh
index 28e4f8a..be5834e 100755
--- a/ruby/version_metadata_TEST_setup.sh
+++ b/ruby/version_metadata_TEST_setup.sh
@@ -34,3 +34,12 @@ END
cd ..
+mkdir -p installed/cat-one/pkg-{one,two}-1 || exit 1
+
+touch installed/cat-one/pkg-one-1/CONTENTS
+touch installed/cat-one/pkg-two-1/CONTENTS
+
+echo "origin_test" > installed/cat-one/pkg-one-1/REPOSITORY
+echo "0" > installed/cat-one/pkg-one-1/SLOT
+echo "0" > installed/cat-one/pkg-two-1/SLOT
+