aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-10-25 12:50:39 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-10-25 12:50:39 +0000
commitddf2a289d8a4cd0784fce235ad923e35834bb16d (patch)
tree2d3507ca114b2bd9119302cf8d4fdc7b1a595736
parent6863d33450e0555938a1a59f0a269813c0f99e68 (diff)
downloadpaludis-ddf2a289d8a4cd0784fce235ad923e35834bb16d.tar.gz
paludis-ddf2a289d8a4cd0784fce235ad923e35834bb16d.tar.xz
Allow access to PackageDatabaseEntry members. From Richard Brown.
-rw-r--r--ruby/package_database_entry.cc65
-rw-r--r--ruby/package_database_entry_TEST.rb42
2 files changed, 107 insertions, 0 deletions
diff --git a/ruby/package_database_entry.cc b/ruby/package_database_entry.cc
index 9a9ef6b..941f61b 100644
--- a/ruby/package_database_entry.cc
+++ b/ruby/package_database_entry.cc
@@ -59,6 +59,65 @@ namespace
}
}
+ VALUE
+ package_database_entry_version(VALUE self)
+ {
+ try
+ {
+ PackageDatabaseEntry * p;
+ Data_Get_Struct(self, PackageDatabaseEntry, p);
+ return version_spec_to_value(p->version);
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ package_database_entry_version_set(VALUE self, VALUE version)
+ {
+ try
+ {
+ PackageDatabaseEntry * p;
+ Data_Get_Struct(self, PackageDatabaseEntry, p);
+ p->version = value_to_version_spec(version);
+ return self;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ template <typename T_, T_ PackageDatabaseEntry::* m_>
+ struct EntryValue
+ {
+ static VALUE
+ fetch(VALUE self)
+ {
+ PackageDatabaseEntry * p;
+ Data_Get_Struct(self, PackageDatabaseEntry, p);
+ return rb_str_new2(stringify(p->*m_).c_str());
+ }
+
+ static VALUE
+ set(VALUE self, VALUE str)
+ {
+ try
+ {
+ PackageDatabaseEntry * p;
+ Data_Get_Struct(self, PackageDatabaseEntry, p);
+ p->*m_ = T_ ((STR2CSTR(str)));
+ return self;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+ };
+
void do_register_package_database_entry()
{
c_package_database_entry = rb_define_class_under(master_class(), "PackageDatabaseEntry", rb_cObject);
@@ -67,6 +126,12 @@ namespace
rb_define_method(c_package_database_entry, "<=>", RUBY_FUNC_CAST(&Common<PackageDatabaseEntry>::compare), 1);
rb_include_module(c_package_database_entry, rb_mComparable);
rb_define_method(c_package_database_entry, "to_s", RUBY_FUNC_CAST(&Common<PackageDatabaseEntry>::to_s), 0);
+ rb_define_method(c_package_database_entry, "name", RUBY_FUNC_CAST((&EntryValue<QualifiedPackageName, &PackageDatabaseEntry::name>::fetch)), 0);
+ rb_define_method(c_package_database_entry, "name=", RUBY_FUNC_CAST((&EntryValue<QualifiedPackageName, &PackageDatabaseEntry::name>::set)), 1);
+ rb_define_method(c_package_database_entry, "version", RUBY_FUNC_CAST(&package_database_entry_version), 0);
+ rb_define_method(c_package_database_entry, "version=", RUBY_FUNC_CAST(&package_database_entry_version_set), 1);
+ rb_define_method(c_package_database_entry, "repository", RUBY_FUNC_CAST((&EntryValue<RepositoryName, &PackageDatabaseEntry::repository>::fetch)), 0);
+ rb_define_method(c_package_database_entry, "repository=", RUBY_FUNC_CAST((&EntryValue<RepositoryName, &PackageDatabaseEntry::repository>::set)), 1);
}
}
diff --git a/ruby/package_database_entry_TEST.rb b/ruby/package_database_entry_TEST.rb
index dae3418..2b4cf53 100644
--- a/ruby/package_database_entry_TEST.rb
+++ b/ruby/package_database_entry_TEST.rb
@@ -42,6 +42,48 @@ class Paludis
def test_to_s
assert_equal "foo/bar-10::moo", PackageDatabaseEntry.new("foo/bar", "10", "moo").to_s
end
+
+ def test_name
+ pde = PackageDatabaseEntry.new('foo/bar', VersionSpec.new('1.0-r1'), 'moo')
+ assert_instance_of String, pde.name
+ assert_equal pde.name ,'foo/bar'
+ end
+
+ def test_name_set
+ pde = PackageDatabaseEntry.new('foo/bar', VersionSpec.new('1.0-r1'), 'moo')
+ pde.name='foo/baz'
+ assert_equal pde.name, 'foo/baz'
+ end
+
+ def test_version
+ pde = PackageDatabaseEntry.new('foo/bar', VersionSpec.new('1.0-r1'), 'moo')
+ assert_instance_of VersionSpec, pde.version
+ assert_equal pde.version ,VersionSpec.new('1.0-r1')
+ pde = PackageDatabaseEntry.new('foo/bar', '1.0-r1', 'moo')
+ assert_instance_of VersionSpec, pde.version
+ assert_equal pde.version ,VersionSpec.new('1.0-r1')
+ end
+
+ def test_version_set
+ pde = PackageDatabaseEntry.new('foo/bar', VersionSpec.new('1.0-r1'), 'moo')
+ pde.version = VersionSpec.new('7')
+ assert_equal pde.version, VersionSpec.new('7')
+ pde.version = '7.1'
+ assert_equal pde.version, VersionSpec.new('7.1')
+ end
+
+ def test_repository
+ pde = PackageDatabaseEntry.new('foo/bar', VersionSpec.new('1.0-r1'), 'moo')
+ assert_instance_of String, pde.repository
+ assert_equal pde.repository ,'moo'
+ end
+
+ def test_repository_set
+ pde = PackageDatabaseEntry.new('foo/bar', VersionSpec.new('1.0-r1'), 'moo')
+ pde.repository='testrepo'
+ assert_equal pde.repository, 'testrepo'
+ end
+
end
end