aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-09-25 16:44:49 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-09-25 16:44:49 +0000
commita0331b77bf92d1069ab2e58e3c66809aa92e3d64 (patch)
treee904d26e6fad51f9ed051bdd619b844ac1a52b89
parent30b2167c0020918c2112bc03963424b48a64f9d4 (diff)
downloadpaludis-a0331b77bf92d1069ab2e58e3c66809aa92e3d64.tar.gz
paludis-a0331b77bf92d1069ab2e58e3c66809aa92e3d64.tar.xz
More Ruby work
-rw-r--r--paludis/package_database.cc29
-rw-r--r--paludis/package_database.hh6
-rw-r--r--ruby/Makefile.am9
-rw-r--r--ruby/default_environment_TEST.rb25
-rw-r--r--ruby/dep_atom.cc91
-rw-r--r--ruby/dep_atom_TEST.rb48
-rw-r--r--ruby/log.cc6
-rw-r--r--ruby/log_TEST.rb14
-rw-r--r--ruby/package_database.cc60
-rw-r--r--ruby/package_database_TEST.rb37
-rwxr-xr-xruby/package_database_TEST_cleanup.sh13
-rwxr-xr-xruby/package_database_TEST_setup.sh63
-rw-r--r--ruby/package_database_entry.cc18
-rw-r--r--ruby/paludis_ruby.cc4
-rw-r--r--ruby/paludis_ruby.hh10
15 files changed, 393 insertions, 40 deletions
diff --git a/paludis/package_database.cc b/paludis/package_database.cc
index 17aa0d5..6b4eaf5 100644
--- a/paludis/package_database.cc
+++ b/paludis/package_database.cc
@@ -309,3 +309,32 @@ PackageDatabase::end_repositories() const
return RepositoryIterator(_imp->repositories.end());
}
+std::ostream &
+paludis::operator<< (std::ostream & o, const InstallState & s)
+{
+ do
+ {
+ switch (s)
+ {
+ case is_installed_only:
+ o << "installed_only";
+ continue;
+
+ case is_uninstalled_only:
+ o << "uninstalled_only";
+ continue;
+
+ case is_either:
+ o << "either";
+ continue;
+
+ case last_install_state:
+ ;
+ }
+
+ throw InternalError(PALUDIS_HERE, "Bad InstallState");
+ } while (false);
+
+ return o;
+}
+
diff --git a/paludis/package_database.hh b/paludis/package_database.hh
index cc15b85..de10721 100644
--- a/paludis/package_database.hh
+++ b/paludis/package_database.hh
@@ -204,7 +204,8 @@ namespace paludis
{
is_installed_only, ///< Installed only
is_uninstalled_only, ///< Uninstalled only
- is_either ///< Either
+ is_either, ///< Either
+ last_install_state
};
/**
@@ -291,6 +292,9 @@ namespace paludis
///\}
};
+
+ std::ostream &
+ operator<< (std::ostream &, const InstallState &);
}
#endif
diff --git a/ruby/Makefile.am b/ruby/Makefile.am
index 6c0e866..d0d0dbf 100644
--- a/ruby/Makefile.am
+++ b/ruby/Makefile.am
@@ -21,6 +21,7 @@ IF_RUBY_TESTS = \
package_database_entry_TEST.rb \
version_spec_TEST.rb \
mask_reasons_TEST.rb \
+ dep_atom_TEST.rb \
package_database_TEST.rb
IF_RUBY_SOURCES = \
@@ -29,11 +30,13 @@ IF_RUBY_SOURCES = \
package_database_entry.cc \
version_spec.cc \
mask_reasons.cc \
+ dep_atom.cc \
log.cc \
package_database.cc
EXTRA_DIST = $(IF_RUBY_TESTS) $(IF_RUBY_SOURCES) \
- default_environment_TEST_setup.sh default_environment_TEST_cleanup.sh
+ default_environment_TEST_setup.sh default_environment_TEST_cleanup.sh \
+ package_database_TEST_setup.sh package_database_TEST_cleanup.sh
TESTS_ENVIRONMENT = env \
PALUDIS_NO_GLOBAL_HOOKS="yes" \
@@ -49,6 +52,7 @@ if ENABLE_RUBY
OUR_OBJECTS = \
default_environment.o \
+ dep_atom.o \
log.o \
mask_reasons.o \
package_database.o \
@@ -72,6 +76,9 @@ paludis_ruby.o : paludis_ruby.cc paludis_ruby.hh
default_environment.o : default_environment.cc paludis_ruby.hh
$(OUR_CXXCOMPILE) -o $@ $(srcdir)/default_environment.cc
+dep_atom.o : dep_atom.cc paludis_ruby.hh
+ $(OUR_CXXCOMPILE) -o $@ $(srcdir)/dep_atom.cc
+
package_database_entry.o : package_database_entry.cc paludis_ruby.hh
$(OUR_CXXCOMPILE) -o $@ $(srcdir)/package_database_entry.cc
diff --git a/ruby/default_environment_TEST.rb b/ruby/default_environment_TEST.rb
index a2630ec..c9c7ba3 100644
--- a/ruby/default_environment_TEST.rb
+++ b/ruby/default_environment_TEST.rb
@@ -23,7 +23,7 @@ ENV["PALUDIS_HOME"] = Dir.getwd().to_s + "/default_environment_TEST_dir/home";
require 'test/unit'
require 'Paludis'
-Paludis::Log.instance.log_level = Paludis::Log::LogLevel::Warning
+Paludis::Log.instance.log_level = Paludis::LogLevel::Warning
class Paludis
@@ -45,8 +45,7 @@ class Paludis
assert ! DefaultEnvironment.instance.query_use("not_enabled")
assert ! DefaultEnvironment.instance.query_use("sometimes_enabled")
- pde = PackageDatabaseEntry.new("foo/bar",
- VersionSpec.new("1.0"), "testrepo")
+ pde = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("1.0"), "testrepo")
assert DefaultEnvironment.instance.query_use("enabled", pde)
assert ! DefaultEnvironment.instance.query_use("not_enabled", pde)
@@ -91,8 +90,7 @@ class Paludis
def test_accept_license
assert DefaultEnvironment.instance.accept_license("test")
- pde = PackageDatabaseEntry.new("foo/bar",
- VersionSpec.new("1.0"), "testrepo")
+ pde = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("1.0"), "testrepo")
assert DefaultEnvironment.instance.accept_license("test", pde)
end
@@ -109,16 +107,14 @@ class Paludis
class TestCase_DefaultEnvironmentMaskReasons < Test::Unit::TestCase
def test_mask_reasons
- p = PackageDatabaseEntry.new("foo/bar",
- VersionSpec.new("1.0"), "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("foo/bar",
- VersionSpec.new("2.0"), "testrepo")
+ p = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("2.0"), "testrepo")
m = DefaultEnvironment.instance.mask_reasons(p)
assert ! m.empty?
@@ -127,8 +123,7 @@ class Paludis
end
def test_mask_reasons_no_such_repo
- p = PackageDatabaseEntry.new("foo/bar",
- VersionSpec.new("1.0"), "nosuchrepo")
+ p = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("1.0"), "nosuchrepo")
assert_raise RuntimeError do
DefaultEnvironment.instance.mask_reasons p
@@ -153,14 +148,6 @@ class Paludis
def test_package_database
assert_kind_of PackageDatabase, db
end
-
- def test_package_database_favourite_repository
- assert_equal "testrepo", db.favourite_repository
- end
-
- def test_package_database_fetch_unique_qualified_package_name
- assert_equal "foo/bar", db.fetch_unique_qualified_package_name("bar")
- end
end
end
diff --git a/ruby/dep_atom.cc b/ruby/dep_atom.cc
new file mode 100644
index 0000000..3759c42
--- /dev/null
+++ b/ruby/dep_atom.cc
@@ -0,0 +1,91 @@
+/* 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/dep_atom.hh>
+#include <ruby.h>
+
+using namespace paludis;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_dep_atom;
+ static VALUE c_package_dep_atom;
+
+ VALUE
+ dep_atom_init(VALUE self)
+ {
+ return self;
+ }
+
+ VALUE
+ package_dep_atom_init(VALUE self, VALUE)
+ {
+ return self;
+ }
+
+ VALUE
+ package_dep_atom_new(VALUE self, VALUE s)
+ {
+ PackageDepAtom::Pointer * ptr(0);
+ try
+ {
+ ptr = new PackageDepAtom::Pointer(new PackageDepAtom(STR2CSTR(s)));
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<PackageDepAtom::Pointer>::free, ptr));
+ rb_obj_call_init(tdata, 1, &s);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ void do_register_dep_atom()
+ {
+ c_dep_atom = rb_define_class_under(master_class(), "DepAtom", rb_cObject);
+ rb_funcall(c_dep_atom, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_package_dep_atom = rb_define_class_under(master_class(), "PackageDepAtom", c_dep_atom);
+ rb_define_singleton_method(c_package_dep_atom, "new", RUBY_FUNC_CAST(&package_dep_atom_new), 1);
+ rb_define_method(c_package_dep_atom, "initialize", RUBY_FUNC_CAST(&package_dep_atom_init), 1);
+ rb_define_method(c_package_dep_atom, "to_s", RUBY_FUNC_CAST(&Common<PackageDepAtom::Pointer>::to_s_via_ptr), 0);
+ }
+}
+
+PackageDepAtom::Pointer
+paludis::ruby::value_to_package_dep_atom(VALUE v)
+{
+ if (T_STRING == TYPE(v))
+ return PackageDepAtom::Pointer(new PackageDepAtom(STR2CSTR(v)));
+ else
+ {
+ PackageDepAtom::Pointer * v_ptr;
+ Data_Get_Struct(v, PackageDepAtom::Pointer, v_ptr);
+ return *v_ptr;
+ }
+}
+
+RegisterRubyClass::Register paludis_ruby_register_dep_atom PALUDIS_ATTRIBUTE((used))
+ (&do_register_dep_atom);
+
diff --git a/ruby/dep_atom_TEST.rb b/ruby/dep_atom_TEST.rb
new file mode 100644
index 0000000..fc1da26
--- /dev/null
+++ b/ruby/dep_atom_TEST.rb
@@ -0,0 +1,48 @@
+#!/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'
+
+class Paludis
+ class TestCase_VersionSpec < Test::Unit::TestCase
+ def test_create
+ v = PackageDepAtom.new(">=foo/bar-1")
+ end
+
+ def test_create_error
+ assert_raise TypeError do
+ v = PackageDepAtom.new(0)
+ end
+ assert_raise PackageDepAtomError do
+ v = PackageDepAtom.new("=sys-apps/foo")
+ end
+ assert_raise NoMethodError do
+ v = DepAtom.new
+ end
+ end
+
+ def test_to_s
+ assert_equal ">=foo/bar-1", PackageDepAtom.new(">=foo/bar-1").to_s
+ end
+ end
+end
+
+
diff --git a/ruby/log.cc b/ruby/log.cc
index 750d8a6..1dd9abb 100644
--- a/ruby/log.cc
+++ b/ruby/log.cc
@@ -29,7 +29,7 @@ using namespace paludis::ruby;
namespace
{
static VALUE c_log;
- static VALUE c_log_log_level;
+ static VALUE c_log_level;
VALUE
log_log_level(VALUE)
@@ -62,10 +62,10 @@ namespace
rb_define_method(c_log, "log_level=", RUBY_FUNC_CAST(&log_log_level_set), 1);
rb_define_method(c_log, "message", RUBY_FUNC_CAST(&log_message), 2);
- c_log_log_level = rb_define_class_under(c_log, "LogLevel", rb_cObject);
+ c_log_level = rb_define_class_under(master_class(), "LogLevel", rb_cObject);
for (LogLevel l(static_cast<LogLevel>(0)), l_end(last_ll) ; l != l_end ;
l = static_cast<LogLevel>(static_cast<int>(l) + 1))
- rb_define_const(c_log_log_level, value_case_to_RubyCase(stringify(l)).c_str(), INT2FIX(l));
+ rb_define_const(c_log_level, value_case_to_RubyCase(stringify(l)).c_str(), INT2FIX(l));
}
}
diff --git a/ruby/log_TEST.rb b/ruby/log_TEST.rb
index 541cd8d..f745594 100644
--- a/ruby/log_TEST.rb
+++ b/ruby/log_TEST.rb
@@ -39,22 +39,22 @@ class Paludis
class TestCase_LogLogLevel < Test::Unit::TestCase
def test_log_level
assert_equal Log.instance.log_level, Log.instance.log_level
- assert Log.instance.log_level >= Log::LogLevel::Debug
- assert Log.instance.log_level <= Log::LogLevel::Silent
+ assert Log.instance.log_level >= LogLevel::Debug
+ assert Log.instance.log_level <= LogLevel::Silent
end
def test_log_level_set
- Log.instance.log_level = Log::LogLevel::Debug;
- assert_equal Log::LogLevel::Debug, Log.instance.log_level
+ Log.instance.log_level = LogLevel::Debug;
+ assert_equal LogLevel::Debug, Log.instance.log_level
- Log.instance.log_level = Log::LogLevel::Warning;
- assert_equal Log::LogLevel::Warning, Log.instance.log_level
+ Log.instance.log_level = LogLevel::Warning;
+ assert_equal LogLevel::Warning, Log.instance.log_level
end
end
class TestCase_LogMessage < Test::Unit::TestCase
def test_log_message
- Log.instance.message Log::LogLevel::Warning, "This is a test warning message"
+ Log.instance.message LogLevel::Warning, "This is a test warning message"
end
def test_log_message_bad
diff --git a/ruby/package_database.cc b/ruby/package_database.cc
index 60a121e..1201bf7 100644
--- a/ruby/package_database.cc
+++ b/ruby/package_database.cc
@@ -30,22 +30,61 @@ using namespace paludis::ruby;
namespace
{
static VALUE c_package_database;
+ static VALUE c_package_database_install_state;
VALUE
package_database_favourite_repository(VALUE self)
{
- PackageDatabase::Pointer * self_ptr;
- Data_Get_Struct(self, PackageDatabase::Pointer, self_ptr);
- return rb_str_new2(stringify((*self_ptr)->favourite_repository()).c_str());
+ try
+ {
+ PackageDatabase::Pointer * self_ptr;
+ Data_Get_Struct(self, PackageDatabase::Pointer, self_ptr);
+ return rb_str_new2(stringify((*self_ptr)->favourite_repository()).c_str());
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
}
VALUE
package_database_fetch_unique_qualified_package_name(VALUE self, VALUE pkg)
{
- PackageDatabase::Pointer * self_ptr;
- Data_Get_Struct(self, PackageDatabase::Pointer, self_ptr);
- return rb_str_new2(stringify((*self_ptr)->fetch_unique_qualified_package_name(
- PackageNamePart(STR2CSTR(pkg)))).c_str());
+ try
+ {
+ PackageDatabase::Pointer * self_ptr;
+ Data_Get_Struct(self, PackageDatabase::Pointer, self_ptr);
+ return rb_str_new2(stringify((*self_ptr)->fetch_unique_qualified_package_name(
+ PackageNamePart(STR2CSTR(pkg)))).c_str());
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ package_database_query(VALUE self, VALUE atom, VALUE state)
+ {
+ try
+ {
+ PackageDatabase::Pointer * self_ptr;
+ Data_Get_Struct(self, PackageDatabase::Pointer, self_ptr);
+
+ PackageDatabaseEntryCollection::ConstPointer items((*self_ptr)->query(
+ value_to_package_dep_atom(atom),
+ static_cast<InstallState>(NUM2INT(state))));
+
+ VALUE result(rb_ary_new());
+ for (PackageDatabaseEntryCollection::Iterator i(items->begin()),
+ i_end(items->end()) ; i != i_end ; ++i)
+ rb_ary_push(result, create_package_database_entry(*i));
+ return result;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
}
void do_register_package_database()
@@ -56,6 +95,13 @@ namespace
RUBY_FUNC_CAST(&package_database_favourite_repository), 0);
rb_define_method(c_package_database, "fetch_unique_qualified_package_name",
RUBY_FUNC_CAST(&package_database_fetch_unique_qualified_package_name), 1);
+ rb_define_method(c_package_database, "query",
+ RUBY_FUNC_CAST(&package_database_query), 2);
+
+ c_package_database_install_state = rb_define_class_under(master_class(), "InstallState", rb_cObject);
+ for (InstallState l(static_cast<InstallState>(0)), l_end(last_install_state) ; l != l_end ;
+ l = static_cast<InstallState>(static_cast<int>(l) + 1))
+ rb_define_const(c_package_database_install_state, value_case_to_RubyCase(stringify(l)).c_str(), INT2FIX(l));
}
}
diff --git a/ruby/package_database_TEST.rb b/ruby/package_database_TEST.rb
index d81a02b..0943a63 100644
--- a/ruby/package_database_TEST.rb
+++ b/ruby/package_database_TEST.rb
@@ -18,9 +18,13 @@
# Place, Suite 330, Boston, MA 02111-1307 USA
#
+ENV["PALUDIS_HOME"] = Dir.getwd().to_s + "/package_database_TEST_dir/home";
+
require 'test/unit'
require 'Paludis'
+Paludis::Log.instance.log_level = Paludis::LogLevel::Warning
+
class Paludis
class TestCase_PackageDatabase < Test::Unit::TestCase
def test_no_create
@@ -29,6 +33,37 @@ class Paludis
end
end
end
-end
+ class TestCase_PackageDatabaseFavouriteRepository < Test::Unit::TestCase
+ def test_package_database_favourite_repository
+ assert_equal "testrepo", DefaultEnvironment.instance.package_database.favourite_repository
+ end
+ end
+
+ class TestCase_PackageDatabaseFetchUniqueQualifiedPackageName < Test::Unit::TestCase
+ def db
+ return DefaultEnvironment.instance.package_database
+ end
+
+ def test_package_database_fetch_unique_qualified_package_name
+ assert_equal "foo/bar", db.fetch_unique_qualified_package_name("bar")
+ end
+ end
+
+ class TestCase_PackageDatabaseQuery < Test::Unit::TestCase
+ def db
+ return DefaultEnvironment.instance.package_database
+ end
+
+ def test_package_database_query
+ a = db.query("=foo/bar-1.0", InstallState::UninstalledOnly)
+ assert_equal a, [ PackageDatabaseEntry.new("foo/bar", "1.0", "testrepo") ]
+
+ a = db.query("foo/bar", InstallState::UninstalledOnly)
+ assert_equal a, [
+ PackageDatabaseEntry.new("foo/bar", "1.0", "testrepo"),
+ PackageDatabaseEntry.new("foo/bar", "2.0", "testrepo") ]
+ end
+ end
+end
diff --git a/ruby/package_database_TEST_cleanup.sh b/ruby/package_database_TEST_cleanup.sh
new file mode 100755
index 0000000..959cd7e
--- /dev/null
+++ b/ruby/package_database_TEST_cleanup.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d package_database_TEST_dir ] ; then
+ rm -fr package_database_TEST_dir
+else
+ true
+fi
+
+
+
+
+
diff --git a/ruby/package_database_TEST_setup.sh b/ruby/package_database_TEST_setup.sh
new file mode 100755
index 0000000..7ca1693
--- /dev/null
+++ b/ruby/package_database_TEST_setup.sh
@@ -0,0 +1,63 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir package_database_TEST_dir || exit 1
+cd package_database_TEST_dir || exit 1
+
+mkdir -p home/.paludis/repositories
+
+cat <<END > home/.paludis/repositories/testrepo.conf
+location = `pwd`/testrepo
+format = portage
+cache = /var/empty
+profiles = \${location}/profiles/testprofile
+END
+
+cat <<END > home/.paludis/keywords.conf
+* test
+~foo/bar-1 ~test
+END
+
+cat <<END > home/.paludis/use.conf
+* enabled
+~foo/bar-1 sometimes_enabled
+END
+
+cat <<END > home/.paludis/licenses.conf
+* *
+END
+
+mkdir -p testrepo/{eclass,distfiles,profiles/testprofile,foo/bar/files} || exit 1
+cd testrepo || exit 1
+echo "testrepo" > profiles/repo_name || exit 1
+cat <<END > profiles/categories || exit 1
+foo
+END
+cat <<END > profiles/testprofile/make.defaults
+ARCH=test
+USERLAND=test
+KERNEL=test
+END
+
+cat <<"END" > foo/bar/bar-1.0.ebuild || exit 1
+DESCRIPTION="Test package"
+HOMEPAGE="http://paludis.berlios.de/"
+SRC_URI=""
+SLOT="0"
+IUSE=""
+LICENSE="GPL-2"
+KEYWORDS="test"
+END
+
+cat <<"END" > foo/bar/bar-2.0.ebuild || exit 1
+DESCRIPTION="Test package"
+HOMEPAGE="http://paludis.berlios.de/"
+SRC_URI=""
+SLOT="0"
+IUSE=""
+LICENSE="GPL-2"
+KEYWORDS="~test"
+END
+cd ..
+
+
diff --git a/ruby/package_database_entry.cc b/ruby/package_database_entry.cc
index b34d1c9..9a1eaf1 100644
--- a/ruby/package_database_entry.cc
+++ b/ruby/package_database_entry.cc
@@ -70,7 +70,23 @@ namespace
}
}
+VALUE
+paludis::ruby::create_package_database_entry(const PackageDatabaseEntry & d)
+{
+ PackageDatabaseEntry * m_ptr(0);
+ try
+ {
+ m_ptr = new PackageDatabaseEntry(d);
+ return Data_Wrap_Struct(c_package_database_entry, 0, &Common<PackageDatabaseEntry>::free, m_ptr);
+ }
+ catch (const std::exception & e)
+ {
+ delete m_ptr;
+ exception_to_ruby_exception(e);
+ }
+
+}
+
RegisterRubyClass::Register paludis_ruby_register_package_database_entry PALUDIS_ATTRIBUTE((used))
(&do_register_package_database_entry);
-
diff --git a/ruby/paludis_ruby.cc b/ruby/paludis_ruby.cc
index 0024b82..a0c5254 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_package_dep_atom_error;
}
RegisterRubyClass::RegisterRubyClass() :
@@ -71,6 +72,8 @@ void paludis::ruby::exception_to_ruby_exception(const std::exception & ee)
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::PackageDepAtomError *>(&ee))
+ rb_raise(c_package_dep_atom_error, dynamic_cast<const paludis::PackageDepAtomError *>(&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());
@@ -114,6 +117,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_package_dep_atom_error = rb_define_class_under(c_master_class, "PackageDepAtomError", rb_eRuntimeError);
RegisterRubyClass::get_instance()->execute();
}
}
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index b2aa80b..50b1c9c 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -44,8 +44,10 @@ namespace paludis
VALUE master_class();
VALUE create_mask_reasons(const MaskReasons &);
VALUE create_package_database(PackageDatabase::Pointer);
+ VALUE create_package_database_entry(const PackageDatabaseEntry &);
VersionSpec value_to_version_spec(VALUE v);
+ PackageDepAtom::Pointer value_to_package_dep_atom(VALUE v);
/* registration */
@@ -96,6 +98,14 @@ namespace paludis
return rb_str_new2(stringify(*self_ptr).c_str());
}
+
+ static VALUE to_s_via_ptr(VALUE self)
+ {
+ T_ * self_ptr;
+ Data_Get_Struct(self, T_, self_ptr);
+
+ return rb_str_new2(stringify(**self_ptr).c_str());
+ }
};
}
}