aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-10-27 12:43:53 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-10-27 12:43:53 +0000
commitc423b05dbe15b3edace80c79faa6ff1a5c4106c1 (patch)
treeab2cad3eeb15fcd12c9b48e58551525e9454a133
parent7f93223dfb2b3f4230affd92bfa6cb75d8abae83 (diff)
downloadpaludis-c423b05dbe15b3edace80c79faa6ff1a5c4106c1.tar.gz
paludis-c423b05dbe15b3edace80c79faa6ff1a5c4106c1.tar.xz
Extend VersionSpec. From Richard Brown
-rw-r--r--ruby/paludis_ruby.cc4
-rw-r--r--ruby/version_spec.cc28
-rw-r--r--ruby/version_spec_TEST.rb12
3 files changed, 44 insertions, 0 deletions
diff --git a/ruby/paludis_ruby.cc b/ruby/paludis_ruby.cc
index ccd64f6..066bea6 100644
--- a/ruby/paludis_ruby.cc
+++ b/ruby/paludis_ruby.cc
@@ -40,6 +40,7 @@ namespace
{
static VALUE c_master_class;
static VALUE c_name_error;
+ static VALUE c_bad_version_spec_error;
static VALUE c_package_dep_atom_error;
static VALUE c_package_database_error;
static VALUE c_package_database_lookup_error;
@@ -77,6 +78,8 @@ void paludis::ruby::exception_to_ruby_exception(const std::exception & ee)
if (0 != dynamic_cast<const paludis::InternalError *>(&ee))
rb_raise(rb_eRuntimeError, "Unexpected paludis::InternalError: %s (%s)",
dynamic_cast<const paludis::InternalError *>(&ee)->message().c_str(), ee.what());
+ else if (0 != dynamic_cast<const paludis::BadVersionSpecError *>(&ee))
+ rb_raise(c_bad_version_spec_error, dynamic_cast<const paludis::BadVersionSpecError *>(&ee)->message().c_str());
else if (0 != dynamic_cast<const paludis::NameError *>(&ee))
rb_raise(c_name_error, dynamic_cast<const paludis::NameError *>(&ee)->message().c_str());
else if (0 != dynamic_cast<const paludis::PackageDepAtomError *>(&ee))
@@ -139,6 +142,7 @@ extern "C"
{
c_master_class = rb_define_class("Paludis", rb_cObject);
c_name_error = rb_define_class_under(c_master_class, "NameError", rb_eRuntimeError);
+ c_bad_version_spec_error = rb_define_class_under(c_master_class, "BadVersionSpecError", c_name_error);
c_package_dep_atom_error = rb_define_class_under(c_master_class, "PackageDepAtomError", rb_eRuntimeError);
c_package_database_error = rb_define_class_under(c_master_class, "PackageDatabaseError", rb_eRuntimeError);
c_package_database_lookup_error = rb_define_class_under(c_master_class, "PackageDatabaseLookupError", c_package_database_error);
diff --git a/ruby/version_spec.cc b/ruby/version_spec.cc
index 8938072..d5d9b88 100644
--- a/ruby/version_spec.cc
+++ b/ruby/version_spec.cc
@@ -54,6 +54,32 @@ namespace
}
}
+ VALUE
+ version_spec_remove_revision(VALUE self)
+ {
+ try
+ {
+ return version_spec_to_value(value_to_version_spec(self).remove_revision());
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ version_spec_revision_only(VALUE self)
+ {
+ try
+ {
+ return rb_str_new2((value_to_version_spec(self).revision_only().c_str()));
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
void do_register_version_spec()
{
c_version_spec = rb_define_class_under(master_class(), "VersionSpec", rb_cObject);
@@ -62,6 +88,8 @@ namespace
rb_define_method(c_version_spec, "<=>", RUBY_FUNC_CAST(&Common<VersionSpec>::compare), 1);
rb_include_module(c_version_spec, rb_mComparable);
rb_define_method(c_version_spec, "to_s", RUBY_FUNC_CAST(&Common<VersionSpec>::to_s), 0);
+ rb_define_method(c_version_spec, "remove_revision", RUBY_FUNC_CAST(&version_spec_remove_revision), 0);
+ rb_define_method(c_version_spec, "revision_only", RUBY_FUNC_CAST(&version_spec_revision_only), 0);
}
}
diff --git a/ruby/version_spec_TEST.rb b/ruby/version_spec_TEST.rb
index 6ca2bd8..2e79786 100644
--- a/ruby/version_spec_TEST.rb
+++ b/ruby/version_spec_TEST.rb
@@ -31,6 +31,10 @@ class Paludis
assert_raise TypeError do
v = VersionSpec.new(0)
end
+
+ assert_raise BadVersionSpecError do
+ v = VersionSpec.new("1.0-r1-x")
+ end
end
def test_compare
@@ -51,6 +55,14 @@ class Paludis
def test_to_s
assert_equal "0.1_alpha2", VersionSpec.new("0.1_alpha2").to_s
end
+
+ def test_remove_revision
+ assert_equal VersionSpec.new('0.1'), VersionSpec.new('0.1-r1').remove_revision
+ end
+
+ def test_version_only
+ assert_equal 'r9', VersionSpec.new('0.1-r9').revision_only
+ end
end
end