aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-09-25 13:55:47 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-09-25 13:55:47 +0000
commit20e7e1c222a2596e716b88318ce838982a9269dd (patch)
tree495178686fe86960512bf01321935bbb28a5a0c8
parent47cd5b987fe1121eab48870f91777c5c8f367145 (diff)
downloadpaludis-20e7e1c222a2596e716b88318ce838982a9269dd.tar.gz
paludis-20e7e1c222a2596e716b88318ce838982a9269dd.tar.xz
Rework Ruby code to avoid using most Name classes.
-rw-r--r--ruby/Makefile.am6
-rw-r--r--ruby/default_environment.cc12
-rw-r--r--ruby/default_environment_TEST.rb55
-rw-r--r--ruby/name.cc212
-rw-r--r--ruby/name_TEST.rb197
-rw-r--r--ruby/package_database.cc7
-rw-r--r--ruby/package_database_entry.cc10
-rw-r--r--ruby/package_database_entry_TEST.rb16
-rw-r--r--ruby/paludis_ruby.cc4
-rw-r--r--ruby/paludis_ruby.hh4
-rw-r--r--ruby/version_spec.cc13
11 files changed, 67 insertions, 469 deletions
diff --git a/ruby/Makefile.am b/ruby/Makefile.am
index 1d6147a..6c0e866 100644
--- a/ruby/Makefile.am
+++ b/ruby/Makefile.am
@@ -17,7 +17,6 @@ MAINTAINERCLEANFILES = Makefile.in
IF_RUBY_TESTS = \
paludis_ruby_TEST.rb \
log_TEST.rb \
- name_TEST.rb \
default_environment_TEST.rb \
package_database_entry_TEST.rb \
version_spec_TEST.rb \
@@ -26,7 +25,6 @@ IF_RUBY_TESTS = \
IF_RUBY_SOURCES = \
paludis_ruby.cc paludis_ruby.hh \
- name.cc \
default_environment.cc \
package_database_entry.cc \
version_spec.cc \
@@ -53,7 +51,6 @@ OUR_OBJECTS = \
default_environment.o \
log.o \
mask_reasons.o \
- name.o \
package_database.o \
package_database_entry.o \
version_spec.o \
@@ -72,9 +69,6 @@ OUR_CXXCOMPILE = $(CXX) -fPIC $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
paludis_ruby.o : paludis_ruby.cc paludis_ruby.hh
$(OUR_CXXCOMPILE) -o $@ $(srcdir)/paludis_ruby.cc
-name.o : name.cc paludis_ruby.hh
- $(OUR_CXXCOMPILE) -o $@ $(srcdir)/name.cc
-
default_environment.o : default_environment.cc paludis_ruby.hh
$(OUR_CXXCOMPILE) -o $@ $(srcdir)/default_environment.cc
diff --git a/ruby/default_environment.cc b/ruby/default_environment.cc
index b9d94b8..fbbe129 100644
--- a/ruby/default_environment.cc
+++ b/ruby/default_environment.cc
@@ -37,14 +37,12 @@ namespace
{
if (1 == argc || 2 == argc)
{
- UseFlagName * use_flag_ptr;
- Data_Get_Struct(argv[0], UseFlagName, use_flag_ptr);
-
PackageDatabaseEntry * pde_ptr(0);
if (2 == argc)
Data_Get_Struct(argv[1], PackageDatabaseEntry, pde_ptr);
- return DefaultEnvironment::get_instance()->query_use(*use_flag_ptr, pde_ptr) ? Qtrue : Qfalse;
+ return DefaultEnvironment::get_instance()->query_use(UseFlagName(
+ STR2CSTR(argv[0])), pde_ptr) ? Qtrue : Qfalse;
}
else
rb_raise(rb_eArgError, "DefaultEnvironment.query_use expects one or two arguments, but got %d", argc);
@@ -62,14 +60,12 @@ namespace
{
if (1 == argc || 2 == argc)
{
- KeywordName * keyword_name_ptr;
- Data_Get_Struct(argv[0], KeywordName, keyword_name_ptr);
-
PackageDatabaseEntry * pde_ptr(0);
if (2 == argc)
Data_Get_Struct(argv[1], PackageDatabaseEntry, pde_ptr);
- return DefaultEnvironment::get_instance()->accept_keyword(*keyword_name_ptr, pde_ptr) ? Qtrue : Qfalse;
+ return DefaultEnvironment::get_instance()->accept_keyword(KeywordName(
+ STR2CSTR(argv[0])), pde_ptr) ? Qtrue : Qfalse;
}
else
rb_raise(rb_eArgError, "DefaultEnvironment.accept_keyword expects one or two arguments, but got %d", argc);
diff --git a/ruby/default_environment_TEST.rb b/ruby/default_environment_TEST.rb
index 1cc12e2..a2630ec 100644
--- a/ruby/default_environment_TEST.rb
+++ b/ruby/default_environment_TEST.rb
@@ -41,16 +41,16 @@ class Paludis
class TestCase_DefaultEnvironmentUse < Test::Unit::TestCase
def test_query_use
- assert DefaultEnvironment.instance.query_use(UseFlagName.new("enabled"))
- assert ! DefaultEnvironment.instance.query_use(UseFlagName.new("not_enabled"))
- assert ! DefaultEnvironment.instance.query_use(UseFlagName.new("sometimes_enabled"))
+ assert DefaultEnvironment.instance.query_use("enabled")
+ assert ! DefaultEnvironment.instance.query_use("not_enabled")
+ assert ! DefaultEnvironment.instance.query_use("sometimes_enabled")
- pde = PackageDatabaseEntry.new(QualifiedPackageName.new("foo/bar"),
- VersionSpec.new("1.0"), RepositoryName.new("testrepo"))
+ pde = PackageDatabaseEntry.new("foo/bar",
+ VersionSpec.new("1.0"), "testrepo")
- assert DefaultEnvironment.instance.query_use(UseFlagName.new("enabled"), pde)
- assert ! DefaultEnvironment.instance.query_use(UseFlagName.new("not_enabled"), pde)
- assert DefaultEnvironment.instance.query_use(UseFlagName.new("sometimes_enabled"), pde)
+ assert DefaultEnvironment.instance.query_use("enabled", pde)
+ assert ! DefaultEnvironment.instance.query_use("not_enabled", pde)
+ assert DefaultEnvironment.instance.query_use("sometimes_enabled", pde)
end
def test_query_use_bad
@@ -58,7 +58,7 @@ class Paludis
DefaultEnvironment.instance.query_use(1, 2, 3)
end
assert_raise TypeError do
- DefaultEnvironment.instance.query_use("not_enabled")
+ DefaultEnvironment.instance.query_use(123)
end
end
@@ -66,16 +66,15 @@ class Paludis
class TestCase_DefaultEnvironmentAcceptKeyword < Test::Unit::TestCase
def test_accept_keyword
- assert DefaultEnvironment.instance.accept_keyword(KeywordName.new("test"))
- assert ! DefaultEnvironment.instance.accept_keyword(KeywordName.new("bad"))
- assert ! DefaultEnvironment.instance.accept_keyword(KeywordName.new("~test"))
+ assert DefaultEnvironment.instance.accept_keyword("test")
+ assert ! DefaultEnvironment.instance.accept_keyword("bad")
+ assert ! DefaultEnvironment.instance.accept_keyword("~test")
- pde = PackageDatabaseEntry.new(QualifiedPackageName.new("foo/bar"),
- VersionSpec.new("1.0"), RepositoryName.new("testrepo"))
+ pde = PackageDatabaseEntry.new("foo/bar", "1.0", "testrepo")
- assert DefaultEnvironment.instance.accept_keyword(KeywordName.new("test"), pde)
- assert ! DefaultEnvironment.instance.accept_keyword(KeywordName.new("bad"), pde)
- assert DefaultEnvironment.instance.accept_keyword(KeywordName.new("~test"), pde)
+ assert DefaultEnvironment.instance.accept_keyword("test", pde)
+ assert ! DefaultEnvironment.instance.accept_keyword("bad", pde)
+ assert DefaultEnvironment.instance.accept_keyword("~test", pde)
end
def test_accept_keyword_bad
@@ -83,7 +82,7 @@ class Paludis
DefaultEnvironment.instance.accept_keyword(1, 2, 3)
end
assert_raise TypeError do
- DefaultEnvironment.instance.accept_keyword("foo")
+ DefaultEnvironment.instance.accept_keyword(123)
end
end
end
@@ -92,8 +91,8 @@ class Paludis
def test_accept_license
assert DefaultEnvironment.instance.accept_license("test")
- pde = PackageDatabaseEntry.new(QualifiedPackageName.new("foo/bar"),
- VersionSpec.new("1.0"), RepositoryName.new("testrepo"))
+ pde = PackageDatabaseEntry.new("foo/bar",
+ VersionSpec.new("1.0"), "testrepo")
assert DefaultEnvironment.instance.accept_license("test", pde)
end
@@ -110,16 +109,16 @@ class Paludis
class TestCase_DefaultEnvironmentMaskReasons < Test::Unit::TestCase
def test_mask_reasons
- p = PackageDatabaseEntry.new(QualifiedPackageName.new("foo/bar"),
- VersionSpec.new("1.0"), RepositoryName.new("testrepo"))
+ p = PackageDatabaseEntry.new("foo/bar",
+ VersionSpec.new("1.0"), "testrepo")
m = DefaultEnvironment.instance.mask_reasons(p)
assert m.empty?
end
def test_mask_reasons_not_empty
- p = PackageDatabaseEntry.new(QualifiedPackageName.new("foo/bar"),
- VersionSpec.new("2.0"), RepositoryName.new("testrepo"))
+ p = PackageDatabaseEntry.new("foo/bar",
+ VersionSpec.new("2.0"), "testrepo")
m = DefaultEnvironment.instance.mask_reasons(p)
assert ! m.empty?
@@ -128,8 +127,8 @@ class Paludis
end
def test_mask_reasons_no_such_repo
- p = PackageDatabaseEntry.new(QualifiedPackageName.new("foo/bar"),
- VersionSpec.new("1.0"), RepositoryName.new("nosuchrepo"))
+ p = PackageDatabaseEntry.new("foo/bar",
+ VersionSpec.new("1.0"), "nosuchrepo")
assert_raise RuntimeError do
DefaultEnvironment.instance.mask_reasons p
@@ -156,11 +155,11 @@ class Paludis
end
def test_package_database_favourite_repository
- assert_equal RepositoryName.new("testrepo"), db.favourite_repository
+ assert_equal "testrepo", db.favourite_repository
end
def test_package_database_fetch_unique_qualified_package_name
- assert_equal QualifiedPackageName.new("foo/bar"), db.fetch_unique_qualified_package_name(PackageNamePart.new("bar"))
+ assert_equal "foo/bar", db.fetch_unique_qualified_package_name("bar")
end
end
diff --git a/ruby/name.cc b/ruby/name.cc
deleted file mode 100644
index a68e299..0000000
--- a/ruby/name.cc
+++ /dev/null
@@ -1,212 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
- *
- * This file is part of the Paludis package manager. Paludis is free software;
- * you can redistribute it and/or modify it under the terms of the GNU General
- * Public License version 2, as published by the Free Software Foundation.
- *
- * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <paludis_ruby.hh>
-#include <paludis/name.hh>
-#include <ruby.h>
-
-using namespace paludis;
-using namespace paludis::ruby;
-
-#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
-
-namespace
-{
- template <typename T_, typename E_>
- struct NameWrapper
- {
- static VALUE c_class;
- static VALUE c_class_except;
-
- static VALUE
- name_part_error_new(VALUE the_class, VALUE value)
- {
- VALUE argv[1];
- std::string * ptr(new std::string(STR2CSTR(value)));
- VALUE tdata(Data_Wrap_Struct(the_class, 0, &Common<std::string>::free, ptr));
- argv[0] = value;
- rb_obj_call_init(tdata, 1, argv);
- rb_call_super(1, &value);
- return tdata;
- }
-
- static VALUE
- name_part_error_init(VALUE self, VALUE)
- {
- return self;
- }
-
- static VALUE
- name_part_new(VALUE the_class, VALUE value)
- {
- VALUE argv[1];
- T_ * ptr(0);
- try
- {
- ptr = new T_(std::string(STR2CSTR(value)));
- VALUE tdata(Data_Wrap_Struct(the_class, 0, &Common<T_>::free, ptr));
- argv[0] = value;
- rb_obj_call_init(tdata, 1, argv);
- return tdata;
- }
- catch (const NameError & e)
- {
- delete ptr;
- rb_raise(c_class_except, e.message().c_str());
- }
- catch (const std::exception & e)
- {
- delete ptr;
- exception_to_ruby_exception(e);
- }
- }
-
- static VALUE
- name_part_init(VALUE self, VALUE)
- {
- return self;
- }
-
- static void do_register(const std::string & name)
- {
- c_class = rb_define_class_under(master_class(), name.c_str(), rb_cObject);
- rb_define_singleton_method(c_class, "new", RUBY_FUNC_CAST(&name_part_new), 1);
- rb_define_method(c_class, "initialize", RUBY_FUNC_CAST(&name_part_init), 1);
- rb_define_method(c_class, "<=>", RUBY_FUNC_CAST(&Common<T_>::compare), 1);
- rb_include_module(c_class, rb_mComparable);
- rb_define_method(c_class, "to_s", RUBY_FUNC_CAST(&Common<T_>::to_s), 0);
-
- c_class_except = rb_define_class_under(master_class(), (name + "Error").c_str(), rb_eRuntimeError);
- rb_define_singleton_method(c_class_except, "new", RUBY_FUNC_CAST(&name_part_error_new), 1);
- rb_define_method(c_class_except, "initialize", RUBY_FUNC_CAST(&name_part_error_init), 1);
- }
- };
-
- template <typename T_, typename E_> VALUE NameWrapper<T_, E_>::c_class;
- template <typename T_, typename E_> VALUE NameWrapper<T_, E_>::c_class_except;
-
- static VALUE c_qualified_package_name;
- static VALUE c_qualified_package_name_error;
-
- VALUE
- category_name_part_plus(VALUE left, VALUE right)
- {
- return rb_funcall(c_qualified_package_name, rb_intern("new"), 2, left, right);
- }
-
- VALUE
- qualified_package_name_init(int, VALUE *, VALUE self)
- {
- return self;
- }
-
- VALUE
- qualified_package_name_new(int argc, VALUE * argv, VALUE self)
- {
- QualifiedPackageName * ptr(0);
- try
- {
- if (1 == argc)
- ptr = new QualifiedPackageName(std::string(STR2CSTR(argv[0])));
- else if (2 == argc)
- {
- CategoryNamePart * cat_ptr;
- Data_Get_Struct(argv[0], CategoryNamePart, cat_ptr);
- PackageNamePart * pkg_ptr;
- Data_Get_Struct(argv[1], PackageNamePart, pkg_ptr);
- ptr = new QualifiedPackageName(*cat_ptr, *pkg_ptr);
- }
- else
- rb_raise(rb_eArgError, "QualifiedPackageName.new expects one or two arguments, but got %d", argc);
-
- VALUE tdata(Data_Wrap_Struct(self, 0, &Common<QualifiedPackageName>::free, ptr));
- rb_obj_call_init(tdata, argc, argv);
- return tdata;
- }
- catch (const NameError & e)
- {
- delete ptr;
- rb_raise(c_qualified_package_name_error, e.message().c_str());
- }
- catch (const std::exception & e)
- {
- delete ptr;
- exception_to_ruby_exception(e);
- }
- }
-
- VALUE
- qualified_package_name_error_new(VALUE the_class, VALUE value)
- {
- VALUE argv[1];
- std::string * ptr(new std::string(STR2CSTR(value)));
- VALUE tdata(Data_Wrap_Struct(the_class, 0, &Common<std::string>::free, ptr));
- argv[0] = value;
- rb_obj_call_init(tdata, 1, argv);
- rb_call_super(1, &value);
- return tdata;
- }
-
- VALUE
- qualified_package_name_error_init(VALUE self, VALUE)
- {
- return self;
- }
-
- void do_register_names()
- {
- NameWrapper<PackageNamePart, PackageNamePartError>::do_register("PackageNamePart");
- NameWrapper<CategoryNamePart, CategoryNamePartError>::do_register("CategoryNamePart");
- NameWrapper<UseFlagName, UseFlagNameError>::do_register("UseFlagName");
- NameWrapper<SlotName, SlotNameError>::do_register("SlotName");
- NameWrapper<RepositoryName, RepositoryNameError>::do_register("RepositoryName");
- NameWrapper<KeywordName, KeywordNameError>::do_register("KeywordName");
-
- rb_define_method(NameWrapper<CategoryNamePart, CategoryNamePartError>::c_class,
- "+", RUBY_FUNC_CAST(&category_name_part_plus), 1);
-
- c_qualified_package_name = rb_define_class_under(master_class(), "QualifiedPackageName", rb_cObject);
- rb_define_singleton_method(c_qualified_package_name, "new", RUBY_FUNC_CAST(&qualified_package_name_new), -1);
- rb_define_method(c_qualified_package_name, "initialize", RUBY_FUNC_CAST(&qualified_package_name_init), -1);
- rb_define_method(c_qualified_package_name, "<=>", RUBY_FUNC_CAST(&Common<QualifiedPackageName>::compare), 1);
- rb_include_module(c_qualified_package_name, rb_mComparable);
- rb_define_method(c_qualified_package_name, "to_s", RUBY_FUNC_CAST(&Common<QualifiedPackageName>::to_s), 0);
-
- c_qualified_package_name_error = rb_define_class_under(master_class(), "QualifiedPackageNameError", rb_eRuntimeError);
- rb_define_singleton_method(c_qualified_package_name_error, "new", RUBY_FUNC_CAST(&qualified_package_name_error_new), 1);
- rb_define_method(c_qualified_package_name_error, "initialize", RUBY_FUNC_CAST(&qualified_package_name_error_init), 1);
- }
-}
-
-VALUE
-paludis::ruby::create_repository_name(const RepositoryName & r)
-{
- return Data_Wrap_Struct((NameWrapper<RepositoryName, RepositoryNameError>::c_class),
- 0, &Common<RepositoryName>::free, new RepositoryName(r));
-}
-
-VALUE
-paludis::ruby::create_qualified_package_name(const QualifiedPackageName & q)
-{
- return Data_Wrap_Struct(c_qualified_package_name, 0, &Common<QualifiedPackageName>::free,
- new QualifiedPackageName(q));
-}
-
-RegisterRubyClass::Register paludis_ruby_register_name PALUDIS_ATTRIBUTE((used)) (&do_register_names);
-
diff --git a/ruby/name_TEST.rb b/ruby/name_TEST.rb
deleted file mode 100644
index 2fd3421..0000000
--- a/ruby/name_TEST.rb
+++ /dev/null
@@ -1,197 +0,0 @@
-#!/usr/bin/ruby
-# vim: set sw=4 sts=4 et tw=80 :
-
-#
-# Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
-#
-# This file is part of the Paludis package manager. Paludis is free software;
-# you can redistribute it and/or modify it under the terms of the GNU General
-# Public License version 2, as published by the Free Software Foundation.
-#
-# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
-# details.
-#
-# You should have received a copy of the GNU General Public License along with
-# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
-# Place, Suite 330, Boston, MA 02111-1307 USA
-#
-
-require 'test/unit'
-require 'Paludis'
-
-module NameTestCaseBase
- def valid_name_foo
- return "foo"
- end
-
- def valid_name_bar
- return "bar"
- end
-
- def bad_name
- return "foo~"
- end
-
- def test_create
- x = name_type().new(valid_name_foo())
- end
-
- def test_assign
- x = name_type().new(valid_name_foo())
- y = x
- end
-
- def test_compare
- x = name_type().new(valid_name_foo())
- y = name_type().new(valid_name_foo())
- z = name_type().new(valid_name_bar())
- assert_equal x, y
- assert_not_equal y, z
- assert_operator z, :<, x
- assert_operator x, :>, z
- assert_raise TypeError do
- x < valid_name_foo()
- end
- end
-
- def test_create_errors
- assert_raise error_type() do
- x = name_type().new(bad_name())
- end
- assert_raise error_type() do
- x = name_type().new("")
- end
- end
-
- def test_to_s
- x = name_type().new(valid_name_foo())
- y = name_type().new(valid_name_bar())
- assert_equal valid_name_foo(), x.to_s
- assert_equal valid_name_bar(), y.to_s
- end
-end
-
-class Paludis
- class TestCase_PackageNamePart < Test::Unit::TestCase
- include NameTestCaseBase
-
- def error_type
- return PackageNamePartError
- end
-
- def name_type
- return PackageNamePart
- end
- end
-
- class TestCase_CategoryNamePart < Test::Unit::TestCase
- include NameTestCaseBase
-
- def error_type
- return CategoryNamePartError
- end
-
- def name_type
- return CategoryNamePart
- end
-
- def test_plus
- q = CategoryNamePart.new("foo") + PackageNamePart.new("bar")
- assert_equal "foo/bar", q.to_s
- end
-
- def test_plus_bad
- assert_raise TypeError do
- q = CategoryNamePart.new("foo") + "bar"
- end
- end
- end
-
- class TestCase_UseFlagName < Test::Unit::TestCase
- include NameTestCaseBase
-
- def error_type
- return UseFlagNameError
- end
-
- def name_type
- return UseFlagName
- end
- end
-
- class TestCase_RepositoryName < Test::Unit::TestCase
- include NameTestCaseBase
-
- def error_type
- return RepositoryNameError
- end
-
- def name_type
- return RepositoryName
- end
- end
-
- class TestCase_SlotName < Test::Unit::TestCase
- include NameTestCaseBase
-
- def error_type
- return SlotNameError
- end
-
- def name_type
- return SlotName
- end
- end
-
- class TestCase_KeywordName < Test::Unit::TestCase
- include NameTestCaseBase
-
- def error_type
- return KeywordNameError
- end
-
- def name_type
- return KeywordName
- end
- end
-
- class TestCase_QualifiedPackageName < Test::Unit::TestCase
- include NameTestCaseBase
-
- def error_type
- return QualifiedPackageNameError
- end
-
- def name_type
- return QualifiedPackageName
- end
-
- def valid_name_foo
- return "foo/foo"
- end
-
- def valid_name_bar
- return "bar/bar"
- end
-
- def test_two_arg_create
- x = QualifiedPackageName.new(CategoryNamePart.new("foo"), PackageNamePart.new("bar"))
- assert_equal "foo/bar", x.to_s
- end
-
- def test_bad_arg_count_create
- assert_raise ArgumentError do
- x = QualifiedPackageName.new("foo", "bar", "baz")
- end
- end
-
- def test_bad_type_create
- assert_raise TypeError do
- x = QualifiedPackageName.new("foo", "bar")
- end
- end
- end
-end
-
diff --git a/ruby/package_database.cc b/ruby/package_database.cc
index 867322c..60a121e 100644
--- a/ruby/package_database.cc
+++ b/ruby/package_database.cc
@@ -36,7 +36,7 @@ namespace
{
PackageDatabase::Pointer * self_ptr;
Data_Get_Struct(self, PackageDatabase::Pointer, self_ptr);
- return create_repository_name((*self_ptr)->favourite_repository());
+ return rb_str_new2(stringify((*self_ptr)->favourite_repository()).c_str());
}
VALUE
@@ -44,9 +44,8 @@ namespace
{
PackageDatabase::Pointer * self_ptr;
Data_Get_Struct(self, PackageDatabase::Pointer, self_ptr);
- PackageNamePart * pkg_ptr;
- Data_Get_Struct(pkg, PackageNamePart, pkg_ptr);
- return create_qualified_package_name((*self_ptr)->fetch_unique_qualified_package_name(*pkg_ptr));
+ return rb_str_new2(stringify((*self_ptr)->fetch_unique_qualified_package_name(
+ PackageNamePart(STR2CSTR(pkg)))).c_str());
}
void do_register_package_database()
diff --git a/ruby/package_database_entry.cc b/ruby/package_database_entry.cc
index 9e6b01b..b34d1c9 100644
--- a/ruby/package_database_entry.cc
+++ b/ruby/package_database_entry.cc
@@ -44,14 +44,10 @@ namespace
PackageDatabaseEntry * ptr(0);
try
{
- QualifiedPackageName * q_ptr;
- Data_Get_Struct(q, QualifiedPackageName, q_ptr);
- VersionSpec * v_ptr;
- Data_Get_Struct(v, VersionSpec, v_ptr);
- RepositoryName * n_ptr;
- Data_Get_Struct(n, RepositoryName, n_ptr);
+ VersionSpec vv(value_to_version_spec(v));
- ptr = new PackageDatabaseEntry(*q_ptr, *v_ptr, *n_ptr);
+ ptr = new PackageDatabaseEntry(QualifiedPackageName(STR2CSTR(q)), vv,
+ RepositoryName(STR2CSTR(n)));
VALUE tdata(Data_Wrap_Struct(self, 0, &Common<PackageDatabaseEntry>::free, ptr));
rb_obj_call_init(tdata, 3, argv);
return tdata;
diff --git a/ruby/package_database_entry_TEST.rb b/ruby/package_database_entry_TEST.rb
index 6049905..dae3418 100644
--- a/ruby/package_database_entry_TEST.rb
+++ b/ruby/package_database_entry_TEST.rb
@@ -23,18 +23,24 @@ require 'Paludis'
class Paludis
class TestCase_PackageDatabaseEntry < Test::Unit::TestCase
def test_create
- v = PackageDatabaseEntry.new(QualifiedPackageName.new("foo/bar"),
- VersionSpec.new("0"), RepositoryName.new("moo"))
+ v = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("0"), "moo")
+ w = PackageDatabaseEntry.new("foo/bar", "0", "moo")
end
def test_create_error
assert_raise TypeError do
- v = PackageDatabaseEntry.new("foo/bar", "0", "moo")
+ v = PackageDatabaseEntry.new("foo/bar", "0", 123)
+ end
+ assert_raise TypeError do
+ v = PackageDatabaseEntry.new("foo/bar", 123, "moo")
+ end
+ assert_raise NameError do
+ v = PackageDatabaseEntry.new("asdf", "0", "moo")
end
end
+
def test_to_s
- assert_equal "foo/bar-10::moo", PackageDatabaseEntry.new(QualifiedPackageName.new("foo/bar"),
- VersionSpec.new("10"), RepositoryName.new("moo")).to_s
+ assert_equal "foo/bar-10::moo", PackageDatabaseEntry.new("foo/bar", "10", "moo").to_s
end
end
end
diff --git a/ruby/paludis_ruby.cc b/ruby/paludis_ruby.cc
index cf7ed74..0024b82 100644
--- a/ruby/paludis_ruby.cc
+++ b/ruby/paludis_ruby.cc
@@ -39,6 +39,7 @@ namespace paludis
namespace
{
static VALUE c_master_class;
+ static VALUE c_name_error;
}
RegisterRubyClass::RegisterRubyClass() :
@@ -68,6 +69,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::NameError *>(&ee))
+ rb_raise(c_name_error, dynamic_cast<const paludis::NameError *>(&ee)->message().c_str());
else if (0 != dynamic_cast<const paludis::Exception *>(&ee))
rb_raise(rb_eRuntimeError, "Caught paludis::Exception: %s (%s)",
dynamic_cast<const paludis::Exception *>(&ee)->message().c_str(), ee.what());
@@ -110,6 +113,7 @@ extern "C"
void Init_Paludis()
{
c_master_class = rb_define_class("Paludis", rb_cObject);
+ c_name_error = rb_define_class_under(c_master_class, "NameError", rb_eRuntimeError);
RegisterRubyClass::get_instance()->execute();
}
}
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index feb3c9e..b2aa80b 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -44,8 +44,8 @@ namespace paludis
VALUE master_class();
VALUE create_mask_reasons(const MaskReasons &);
VALUE create_package_database(PackageDatabase::Pointer);
- VALUE create_repository_name(const RepositoryName &);
- VALUE create_qualified_package_name(const QualifiedPackageName &);
+
+ VersionSpec value_to_version_spec(VALUE v);
/* registration */
diff --git a/ruby/version_spec.cc b/ruby/version_spec.cc
index 6941e55..24f6b39 100644
--- a/ruby/version_spec.cc
+++ b/ruby/version_spec.cc
@@ -65,6 +65,19 @@ namespace
}
}
+VersionSpec
+paludis::ruby::value_to_version_spec(VALUE v)
+{
+ if (T_STRING == TYPE(v))
+ return VersionSpec(STR2CSTR(v));
+ else
+ {
+ VersionSpec * v_ptr;
+ Data_Get_Struct(v, VersionSpec, v_ptr);
+ return *v_ptr;
+ }
+}
+
RegisterRubyClass::Register paludis_ruby_register_version_spec PALUDIS_ATTRIBUTE((used))
(&do_register_version_spec);