aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-09-24 00:44:30 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-09-24 00:44:30 +0000
commit847fb19e4c4f6f3ee74ded495560ea88011e0bb8 (patch)
tree2ab3d663d18d4d40d4fe8876195b58c3308f1008
parent4bdfcd357fb28620d69443af3ce28556d15007a4 (diff)
downloadpaludis-847fb19e4c4f6f3ee74ded495560ea88011e0bb8.tar.gz
paludis-847fb19e4c4f6f3ee74ded495560ea88011e0bb8.tar.xz
More Ruby work.
-rw-r--r--ruby/Makefile.am14
-rw-r--r--ruby/default_environment.cc14
-rw-r--r--ruby/default_environment_TEST.rb18
-rw-r--r--ruby/log.cc10
-rw-r--r--ruby/log_TEST.rb16
-rw-r--r--ruby/mask_reasons.cc6
-rw-r--r--ruby/name.cc14
-rw-r--r--ruby/package_database.cc81
-rw-r--r--ruby/package_database_TEST.rb34
-rw-r--r--ruby/paludis_ruby.hh4
10 files changed, 200 insertions, 11 deletions
diff --git a/ruby/Makefile.am b/ruby/Makefile.am
index 0642746..1d6147a 100644
--- a/ruby/Makefile.am
+++ b/ruby/Makefile.am
@@ -16,12 +16,13 @@ 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 \
mask_reasons_TEST.rb \
- log_TEST.rb
+ package_database_TEST.rb
IF_RUBY_SOURCES = \
paludis_ruby.cc paludis_ruby.hh \
@@ -30,7 +31,8 @@ IF_RUBY_SOURCES = \
package_database_entry.cc \
version_spec.cc \
mask_reasons.cc \
- log.cc
+ log.cc \
+ package_database.cc
EXTRA_DIST = $(IF_RUBY_TESTS) $(IF_RUBY_SOURCES) \
default_environment_TEST_setup.sh default_environment_TEST_cleanup.sh
@@ -42,7 +44,7 @@ TESTS_ENVIRONMENT = env \
PALUDIS_EBUILD_DIR_FALLBACK="`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/ebuild/`" \
PALUDIS_REPOSITORY_SO_DIR="`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/repositories`" \
SYSCONFDIR="$(sysconfdir)" \
- LD_LIBRARY_PATH="`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/.libs`:`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/repositories/nothing/.libs`:`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/repositories/virtuals/.libs`" \
+ LD_LIBRARY_PATH="`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/.libs`" \
bash $(top_srcdir)/test/run_test.sh "ruby -I ./.libs/"
if ENABLE_RUBY
@@ -52,6 +54,7 @@ OUR_OBJECTS = \
log.o \
mask_reasons.o \
name.o \
+ package_database.o \
package_database_entry.o \
version_spec.o \
paludis_ruby.o
@@ -78,6 +81,9 @@ default_environment.o : default_environment.cc paludis_ruby.hh
package_database_entry.o : package_database_entry.cc paludis_ruby.hh
$(OUR_CXXCOMPILE) -o $@ $(srcdir)/package_database_entry.cc
+package_database.o : package_database.cc paludis_ruby.hh
+ $(OUR_CXXCOMPILE) -o $@ $(srcdir)/package_database.cc
+
version_spec.o : version_spec.cc paludis_ruby.hh
$(OUR_CXXCOMPILE) -o $@ $(srcdir)/version_spec.cc
@@ -95,8 +101,6 @@ log.o : log.cc paludis_ruby.hh
-I@RUBY_SITEARCHDIR@ -l@RUBY_SONAME@ \
-o $@ \
$(top_builddir)/paludis/.libs/libpaludis.so \
- $(top_builddir)/paludis/repositories/nothing/.libs/libpaludisnothingrepository.so \
- $(top_builddir)/paludis/repositories/virtuals/.libs/libpaludisvirtualsrepository.so \
$^
Paludis.so : $(OUR_OBJECTS)
diff --git a/ruby/default_environment.cc b/ruby/default_environment.cc
index 23c2ac8..b9d94b8 100644
--- a/ruby/default_environment.cc
+++ b/ruby/default_environment.cc
@@ -119,6 +119,19 @@ namespace
}
}
+ VALUE
+ default_environment_package_database(VALUE)
+ {
+ try
+ {
+ return create_package_database(DefaultEnvironment::get_instance()->package_database());
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
void do_register_default_environment()
{
rb_require("singleton");
@@ -129,6 +142,7 @@ namespace
rb_define_method(c_default_environment, "accept_keyword", RUBY_FUNC_CAST(&default_environment_accept_keyword), -1);
rb_define_method(c_default_environment, "accept_license", RUBY_FUNC_CAST(&default_environment_accept_license), -1);
rb_define_method(c_default_environment, "mask_reasons", RUBY_FUNC_CAST(&default_environment_mask_reasons), 1);
+ rb_define_method(c_default_environment, "package_database", RUBY_FUNC_CAST(&default_environment_package_database), 0);
}
}
diff --git a/ruby/default_environment_TEST.rb b/ruby/default_environment_TEST.rb
index f1d51c0..1cc12e2 100644
--- a/ruby/default_environment_TEST.rb
+++ b/ruby/default_environment_TEST.rb
@@ -146,5 +146,23 @@ class Paludis
end
end
+ class TestCase_PackageDatabase < Test::Unit::TestCase
+ def db
+ DefaultEnvironment.instance.package_database
+ end
+
+ def test_package_database
+ assert_kind_of PackageDatabase, db
+ end
+
+ def test_package_database_favourite_repository
+ assert_equal RepositoryName.new("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"))
+ end
+ end
+
end
diff --git a/ruby/log.cc b/ruby/log.cc
index 9595494..750d8a6 100644
--- a/ruby/log.cc
+++ b/ruby/log.cc
@@ -44,6 +44,14 @@ namespace
return self;
}
+ VALUE
+ log_message(VALUE self, VALUE log_level, VALUE message)
+ {
+ Log::get_instance()->message(static_cast<LogLevel>(NUM2INT(log_level)), lc_no_context,
+ stringify(STR2CSTR(message)));
+ return self;
+ }
+
void do_register_log()
{
rb_require("singleton");
@@ -52,7 +60,7 @@ namespace
rb_funcall(rb_const_get(rb_cObject, rb_intern("Singleton")), rb_intern("included"), 1, c_log);
rb_define_method(c_log, "log_level", RUBY_FUNC_CAST(&log_log_level), 0);
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);
+ 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);
for (LogLevel l(static_cast<LogLevel>(0)), l_end(last_ll) ; l != l_end ;
diff --git a/ruby/log_TEST.rb b/ruby/log_TEST.rb
index 022ec29..541cd8d 100644
--- a/ruby/log_TEST.rb
+++ b/ruby/log_TEST.rb
@@ -51,5 +51,21 @@ class Paludis
assert_equal Log::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"
+ end
+
+ def test_log_message_bad
+ assert_raise ArgumentError do
+ Log.instance.message "This should fail"
+ end
+
+ assert_raise TypeError do
+ Log.instance.message "Warning", "This should fail"
+ end
+ end
+ end
end
diff --git a/ruby/mask_reasons.cc b/ruby/mask_reasons.cc
index 1fa9f6b..85f77e0 100644
--- a/ruby/mask_reasons.cc
+++ b/ruby/mask_reasons.cc
@@ -90,11 +90,7 @@ namespace
VALUE
paludis::ruby::create_mask_reasons(const MaskReasons & m)
{
- VALUE result(rb_funcall(c_mask_reasons, rb_intern("new"), 0));
- MaskReasons * m_ptr;
- Data_Get_Struct(result, MaskReasons, m_ptr);
- *m_ptr = m;
- return result;
+ return Data_Wrap_Struct(c_mask_reasons, 0, &Common<MaskReasons>::free, new MaskReasons(m));
}
RegisterRubyClass::Register paludis_ruby_register_mask_reasons PALUDIS_ATTRIBUTE((used))
diff --git a/ruby/name.cc b/ruby/name.cc
index b0e9b2e..a68e299 100644
--- a/ruby/name.cc
+++ b/ruby/name.cc
@@ -194,5 +194,19 @@ namespace
}
}
+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/package_database.cc b/ruby/package_database.cc
new file mode 100644
index 0000000..867322c
--- /dev/null
+++ b/ruby/package_database.cc
@@ -0,0 +1,81 @@
+/* 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/package_database.hh>
+#include <paludis/util/stringify.hh>
+#include <ruby.h>
+
+using namespace paludis;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_package_database;
+
+ VALUE
+ package_database_favourite_repository(VALUE self)
+ {
+ PackageDatabase::Pointer * self_ptr;
+ Data_Get_Struct(self, PackageDatabase::Pointer, self_ptr);
+ return create_repository_name((*self_ptr)->favourite_repository());
+ }
+
+ VALUE
+ package_database_fetch_unique_qualified_package_name(VALUE self, VALUE pkg)
+ {
+ 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));
+ }
+
+ void do_register_package_database()
+ {
+ c_package_database = rb_define_class_under(master_class(), "PackageDatabase", rb_cObject);
+ rb_funcall(c_package_database, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_package_database, "favourite_repository",
+ 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);
+ }
+}
+
+VALUE
+paludis::ruby::create_package_database(PackageDatabase::Pointer m)
+{
+ PackageDatabase::Pointer * m_ptr(0);
+ try
+ {
+ m_ptr = new PackageDatabase::Pointer(m);
+ return Data_Wrap_Struct(c_package_database, 0, &Common<PackageDatabase::Pointer>::free, m_ptr);
+ }
+ catch (const std::exception & e)
+ {
+ delete m_ptr;
+ exception_to_ruby_exception(e);
+ }
+}
+
+RegisterRubyClass::Register paludis_ruby_register_package_database PALUDIS_ATTRIBUTE((used))
+ (&do_register_package_database);
+
diff --git a/ruby/package_database_TEST.rb b/ruby/package_database_TEST.rb
new file mode 100644
index 0000000..d81a02b
--- /dev/null
+++ b/ruby/package_database_TEST.rb
@@ -0,0 +1,34 @@
+#!/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_PackageDatabase < Test::Unit::TestCase
+ def test_no_create
+ assert_raise NoMethodError do
+ p = PackageDatabase.new
+ end
+ end
+ end
+end
+
+
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index 93b2119..feb3c9e 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -25,6 +25,7 @@
#include <paludis/util/attributes.hh>
#include <paludis/util/exception.hh>
#include <paludis/util/compare.hh>
+#include <paludis/package_database.hh>
#include <paludis/mask_reasons.hh>
#include <ruby.h>
@@ -42,6 +43,9 @@ 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 &);
/* registration */