aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Alexander Færøy <eroyf@eroyf.org> 2007-05-07 17:05:53 +0000
committerAvatar Alexander Færøy <eroyf@eroyf.org> 2007-05-07 17:05:53 +0000
commit010781b30e774e6c3ce16a7f23956ceb0b1939db (patch)
treea64cf5dda3fd096e9a8207bd26ba478c7c1d13c2
parentea4b60309ffe0ef403898dc67479f3e58da57a5c (diff)
downloadpaludis-010781b30e774e6c3ce16a7f23956ceb0b1939db.tar.gz
paludis-010781b30e774e6c3ce16a7f23956ceb0b1939db.tar.xz
Added Ruby bindings to the new query objects.
-rw-r--r--ruby/query.cc99
-rw-r--r--ruby/query_TEST.rb55
2 files changed, 154 insertions, 0 deletions
diff --git a/ruby/query.cc b/ruby/query.cc
index 0a37f9c..91eff1e 100644
--- a/ruby/query.cc
+++ b/ruby/query.cc
@@ -2,6 +2,7 @@
/*
* Copyright (c) 2007 Richard Brown <rbrown@gentoo.org>
+ * Copyright (c) 2007 Alexander Færøy <eroyf@gentoo.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
@@ -38,6 +39,9 @@ namespace
static VALUE c_repository_has_installable_interface;
static VALUE c_repository_has_uninstallable_interface;
static VALUE c_installed_at_root;
+ static VALUE c_repository;
+ static VALUE c_all;
+ static VALUE c_category;
VALUE
query_to_value(const Query & v)
@@ -163,6 +167,77 @@ namespace
}
}
+ /*
+ * call-seq:
+ * Repository.new(repository_name)
+ *
+ *
+ */
+ VALUE
+ repository_new(VALUE self, VALUE repository_name)
+ {
+ query::Repository * ptr;
+ try
+ {
+ ptr = new query::Repository(RepositoryName(StringValuePtr(repository_name)));
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<query::Repository>::free, ptr));
+ rb_obj_call_init(tdata, 1, &repository_name);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
+ * call-seq:
+ * All.new()
+ *
+ *
+ */
+ VALUE
+ all_new(VALUE self)
+ {
+ query::All * ptr(0);
+ try
+ {
+ ptr = new query::All();
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<query::All>::free, ptr));
+ rb_obj_call_init(tdata, 0, 0);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
+ * call-seq
+ * Category.new(category_name)
+ *
+ *
+ */
+ VALUE
+ category_new(VALUE self, VALUE category_name)
+ {
+ query::Category * ptr(0);
+ try
+ {
+ ptr = new query::Category(CategoryNamePart(StringValuePtr(category_name)));
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<query::Category>::free, ptr));
+ rb_obj_call_init(tdata, 1, &category_name);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
void do_register_query()
{
@@ -246,6 +321,30 @@ namespace
c_installed_at_root = rb_define_class_under(c_query_module,
"InstalledAtRoot", c_query);
rb_define_singleton_method(c_installed_at_root, "new", RUBY_FUNC_CAST(&installed_at_root_new), 1);
+
+ /*
+ * Document-class: Paludis::Query::Repository
+ *
+ * Fetch packages that are installed at a particular repository.
+ */
+ c_repository = rb_define_class_under(c_query_module, "Repository", c_query);
+ rb_define_singleton_method(c_repository, "new", RUBY_FUNC_CAST(&repository_new), 1);
+
+ /*
+ * Document-class: Paludis::Query::All
+ *
+ * Fetch all packages.
+ */
+ c_all = rb_define_class_under(c_query_module, "All", c_query);
+ rb_define_singleton_method(c_all, "new", RUBY_FUNC_CAST(&all_new), 0);
+
+ /*
+ * Document-class: Paludis::Query::Category
+ *
+ * Fetch all packages from a particular category.
+ */
+ c_category = rb_define_class_under(c_query_module, "Category", c_query);
+ rb_define_singleton_method(c_category, "new", RUBY_FUNC_CAST(&category_new), 1);
}
}
diff --git a/ruby/query_TEST.rb b/ruby/query_TEST.rb
index af9ea58..c29b94b 100644
--- a/ruby/query_TEST.rb
+++ b/ruby/query_TEST.rb
@@ -3,6 +3,7 @@
#
# Copyright (c) 2007 Richard Brown <rbrown@gentoo.org>
+# Copyright (c) 2007 Alexander Færøy <eroyf@gentoo.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
@@ -161,5 +162,59 @@ module Paludis
assert_kind_of Query::Query, get_query
end
end
+
+ class TestCase_Repository < Test::Unit::TestCase
+ def get_query
+ Query::Repository.new("gentoo")
+ end
+
+ def test_create
+ assert_nothing_raised do
+ get_query
+ end
+ end
+
+ def test_and
+ q = get_query
+ assert_respond_to q, :&
+ assert_kind_of Query::Query, get_query
+ end
+ end
+
+ class TestCase_All < Test::Unit::TestCase
+ def get_query
+ Query::All.new
+ end
+
+ def test_create
+ assert_nothing_raised do
+ get_query
+ end
+ end
+
+ def test_and
+ q = get_query
+ assert_respond_to q, :&
+ assert_kind_of Query::Query, get_query
+ end
+ end
+
+ class TestCase_Category < Test::Unit::TestCase
+ def get_query
+ Query::Category.new("foo-bar")
+ end
+
+ def test_create
+ assert_nothing_raised do
+ get_query
+ end
+ end
+
+ def test_and
+ q = get_query
+ assert_respond_to q, :&
+ assert_kind_of Query::Query, get_query
+ end
+ end
end