aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-02-04 10:39:26 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-02-04 10:39:26 +0000
commitf3166495811fcad0fd2482984b2f618f498f6b19 (patch)
treef6b75a88c81fc08e4c4ba4814db942e51ea67524
parenta7119c8130cd8bf749ef46d072f5d1d84dc26d48 (diff)
downloadpaludis-f3166495811fcad0fd2482984b2f618f498f6b19.tar.gz
paludis-f3166495811fcad0fd2482984b2f618f498f6b19.tar.xz
Add DepTag to ruby binding.
-rw-r--r--ruby/Makefile.am6
-rw-r--r--ruby/dep_list.cc28
-rw-r--r--ruby/dep_list_TEST.rb7
-rw-r--r--ruby/dep_tag.cc248
-rw-r--r--ruby/dep_tag_TEST.rb136
-rw-r--r--ruby/paludis_ruby.hh1
6 files changed, 421 insertions, 5 deletions
diff --git a/ruby/Makefile.am b/ruby/Makefile.am
index 5dbfa45..14c4a59 100644
--- a/ruby/Makefile.am
+++ b/ruby/Makefile.am
@@ -29,7 +29,8 @@ IF_RUBY_TESTS = \
portage_dep_parser_TEST.rb \
qualified_package_name_TEST.rb \
contents_TEST.rb \
- dep_list_TEST.rb
+ dep_list_TEST.rb \
+ dep_tag_TEST.rb
IF_RUBY_QA_TESTS = \
message_TEST.rb \
@@ -52,7 +53,8 @@ IF_RUBY_SOURCES = \
portage_dep_parser.cc \
qualified_package_name.cc \
contents.cc \
- dep_list.cc
+ dep_list.cc \
+ dep_tag.cc
IF_RUBY_QA_SOURCES = \
message.cc \
diff --git a/ruby/dep_list.cc b/ruby/dep_list.cc
index 40156c1..f69caa1 100644
--- a/ruby/dep_list.cc
+++ b/ruby/dep_list.cc
@@ -994,6 +994,33 @@ namespace
/*
* call-seq:
+ * tags -> Array
+ *
+ * Our DepTags
+ */
+ VALUE
+ dep_list_entry_tags(VALUE self)
+ {
+ try
+ {
+ DepListEntry * p;
+ Data_Get_Struct(self, DepListEntry, p);
+
+ VALUE result(rb_ary_new());
+ for (DepListEntryTags::Iterator r(p->tags->begin()),
+ r_end(p->tags->end()) ; r != r_end ; ++r)
+ rb_ary_push(result, dep_tag_to_value((*r).tag));
+
+ return result;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
+ * call-seq:
* entry_state -> DepListEntryState
*
* Our DepListEntryState.
@@ -1462,6 +1489,7 @@ namespace
rb_define_method(c_dep_list_entry, "metadata", RUBY_FUNC_CAST(&dep_list_entry_metadata),0);
rb_define_method(c_dep_list_entry, "destinations", RUBY_FUNC_CAST(&dep_list_entry_destinations),0);
rb_define_method(c_dep_list_entry, "state", RUBY_FUNC_CAST(&dep_list_entry_state),0);
+ rb_define_method(c_dep_list_entry, "tags", RUBY_FUNC_CAST(&dep_list_entry_tags),0);
/*
* Document-class: DepListOverrideMasks
diff --git a/ruby/dep_list_TEST.rb b/ruby/dep_list_TEST.rb
index 494c145..afac50e 100644
--- a/ruby/dep_list_TEST.rb
+++ b/ruby/dep_list_TEST.rb
@@ -241,9 +241,10 @@ module Paludis
def test_methods
dep_list_entry = dle
- {:package => PackageDatabaseEntry, :metadata => VersionMetadata,
- :destinations => Array, :state=> Integer}.each_pair do |method, returns|
-
+ {
+ :package => PackageDatabaseEntry, :metadata => VersionMetadata,
+ :destinations => Array, :state=> Integer, :tags => Array
+ }.each_pair do |method, returns|
assert_respond_to dep_list_entry, method
assert_kind_of returns, dep_list_entry.send(method)
end
diff --git a/ruby/dep_tag.cc b/ruby/dep_tag.cc
new file mode 100644
index 0000000..d3490e2
--- /dev/null
+++ b/ruby/dep_tag.cc
@@ -0,0 +1,248 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Richard Brown <mynamewasgone@gmail.com>
+ *
+ * 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_tag.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_tag;
+ static VALUE c_dependency_dep_tag;
+ static VALUE c_glsa_dep_tag;
+ static VALUE c_general_set_dep_tag;
+
+ VALUE
+ dep_tag_init(VALUE self, VALUE)
+ {
+ return self;
+ }
+
+ VALUE
+ dep_tag_init_1(int, VALUE*, VALUE self)
+ {
+ return self;
+ }
+
+ VALUE
+ dependency_dep_tag_new(VALUE self, VALUE pde)
+ {
+ std::tr1::shared_ptr<const DependencyDepTag> * ptr(0);
+ try
+ {
+ ptr = new std::tr1::shared_ptr<const DependencyDepTag>(new DependencyDepTag(value_to_package_database_entry(pde)));
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<std::tr1::shared_ptr<const DependencyDepTag> >::free, ptr));
+ rb_obj_call_init(tdata, 1, &pde);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ glsa_dep_tag_new(int argc, VALUE * argv, VALUE self)
+ {
+ if (2 != argc)
+ rb_raise(rb_eArgError, "GLSADepTag expects two arguments, but got %d",argc);
+
+ std::tr1::shared_ptr<const GLSADepTag> * ptr(0);
+ try
+ {
+ ptr = new std::tr1::shared_ptr<const GLSADepTag>(new GLSADepTag(StringValuePtr(argv[0]), StringValuePtr(argv[1])));
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<std::tr1::shared_ptr<const GLSADepTag> >::free, ptr));
+ rb_obj_call_init(tdata, argc, argv);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ general_set_dep_tag_new(int argc, VALUE * argv, VALUE self)
+ {
+ if (2 != argc)
+ rb_raise(rb_eArgError, "GeneralSetDepTag expects two arguments, but got %d",argc);
+
+ std::tr1::shared_ptr<const GeneralSetDepTag> * ptr(0);
+ try
+ {
+ ptr = new std::tr1::shared_ptr<const GeneralSetDepTag>(new GeneralSetDepTag(SetName(StringValuePtr(argv[0])), StringValuePtr(argv[1])));
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<std::tr1::shared_ptr<const GeneralSetDepTag> >::free, ptr));
+ rb_obj_call_init(tdata, argc, argv);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
+ * Document-method: short_text
+ *
+ * call-seq:
+ * short_text -> String
+ *
+ * Fetch our short text (for example, 'GLSA-1234') that is
+ * displayed with the dep list entry.
+ */
+ /*
+ * Document-method: category
+ *
+ * call-seq:
+ * category -> String
+ *
+ * Fetch our DepTagCategory's tag.
+ */
+ /*
+ * Document-method: glsa_title
+ *
+ * call-seq:
+ * glsa_title -> String
+ *
+ * Fetch our GLSA title (for example, 'Yet another PHP remote access hole').
+ */
+ /*
+ * Document-method: source
+ *
+ * call-seq:
+ * source -> String
+ *
+ * From which repository or environment did we originate?
+ */
+ template <typename T_, std::string (T_::* m_) () const>
+ struct DepTagThings
+ {
+ static VALUE
+ fetch(VALUE self)
+ {
+ std::tr1::shared_ptr<const T_> * ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<const T_>, ptr);
+ return rb_str_new2((((**ptr).*m_)()).c_str());
+ }
+ };
+
+ void do_register_dep_tag()
+ {
+ /*
+ * Document-class: Paludis::DepTag
+ *
+ * A DepTag can be associated with a PackageDepAtom, and is transferred onto any associated DepListEntry instances.
+ *
+ * It is used for tagging dep list entries visually, for example to indicate an associated GLSA.
+ */
+ c_dep_tag = rb_define_class_under(paludis_module(), "DepTag", rb_cObject);
+ rb_funcall(c_dep_tag, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_dep_tag, "initialize", RUBY_FUNC_CAST(&dep_tag_init_1), -1);
+ rb_define_method(c_dep_tag, "short_text", RUBY_FUNC_CAST((&DepTagThings<DepTag,&DepTag::short_text>::fetch)), 0);
+ rb_define_method(c_dep_tag, "category", RUBY_FUNC_CAST((&DepTagThings<DepTag,&DepTag::category>::fetch)), 0);
+
+ /*
+ * Document-class: Paludis::DependencyDepTag
+ *
+ * DepTag subclass for dependencies.
+ */
+ c_dependency_dep_tag = rb_define_class_under(paludis_module(), "DependencyDepTag", c_dep_tag);
+ rb_define_singleton_method(c_dependency_dep_tag, "new", RUBY_FUNC_CAST(&dependency_dep_tag_new), 1);
+ rb_define_method(c_dependency_dep_tag, "initialize", RUBY_FUNC_CAST(&dep_tag_init), 1);
+
+ /*
+ * Document-class: Paludis::GLSADepTag
+ *
+ * DepTag subclass for GLSAs.
+ */
+ c_glsa_dep_tag = rb_define_class_under(paludis_module(), "GLSADepTag", c_dep_tag);
+ rb_define_singleton_method(c_glsa_dep_tag, "new", RUBY_FUNC_CAST(&glsa_dep_tag_new), -1);
+ rb_define_method(c_glsa_dep_tag, "glsa_title", RUBY_FUNC_CAST((&DepTagThings<GLSADepTag,
+ &GLSADepTag::glsa_title>::fetch)), 0);
+
+ /*
+ * Document-class: Paludis::GeneralSetDepTag
+ *
+ * DepTag subclass for general sets.
+ */
+ c_general_set_dep_tag = rb_define_class_under(paludis_module(), "GeneralSetDepTag", c_dep_tag);
+ rb_define_singleton_method(c_general_set_dep_tag, "new", RUBY_FUNC_CAST(&general_set_dep_tag_new), -1);
+ rb_define_method(c_general_set_dep_tag, "source", RUBY_FUNC_CAST((&DepTagThings<GeneralSetDepTag,
+ &GeneralSetDepTag::source>::fetch)), 0);
+ }
+}
+
+VALUE
+paludis::ruby::dep_tag_to_value(std::tr1::shared_ptr<const DepTag> m)
+{
+ struct V :
+ DepTagVisitorTypes::ConstVisitor
+ {
+ VALUE value;
+ std::tr1::shared_ptr<const DepTag> mm;
+
+ V(std::tr1::shared_ptr<const DepTag> _m) :
+ mm(_m)
+ {
+ }
+
+ void visit(const DependencyDepTag *)
+ {
+ value = Data_Wrap_Struct(c_dependency_dep_tag, 0, &Common<std::tr1::shared_ptr<const DependencyDepTag> >::free,
+ new std::tr1::shared_ptr<const DependencyDepTag>(std::tr1::static_pointer_cast<const DependencyDepTag>(mm)));
+ }
+
+ void visit(const GLSADepTag *)
+ {
+ value = Data_Wrap_Struct(c_glsa_dep_tag, 0, &Common<std::tr1::shared_ptr<const GLSADepTag> >::free,
+ new std::tr1::shared_ptr<const GLSADepTag>(std::tr1::static_pointer_cast<const GLSADepTag>(mm)));
+ }
+
+ void visit(const GeneralSetDepTag *)
+ {
+ value = Data_Wrap_Struct(c_general_set_dep_tag, 0, &Common<std::tr1::shared_ptr<const GeneralSetDepTag> >::free,
+ new std::tr1::shared_ptr<const GeneralSetDepTag>(std::tr1::static_pointer_cast<const GeneralSetDepTag>(mm)));
+ }
+ };
+
+ std::tr1::shared_ptr<const DepTag> * m_ptr(0);
+ try
+ {
+ V v(m);
+ m->accept(&v);
+ return v.value;
+ }
+ catch (const std::exception & e)
+ {
+ delete m_ptr;
+ exception_to_ruby_exception(e);
+ }
+}
+
+RegisterRubyClass::Register paludis_ruby_register_dep_tag PALUDIS_ATTRIBUTE((used))
+ (&do_register_dep_tag);
+
diff --git a/ruby/dep_tag_TEST.rb b/ruby/dep_tag_TEST.rb
new file mode 100644
index 0000000..c210f88
--- /dev/null
+++ b/ruby/dep_tag_TEST.rb
@@ -0,0 +1,136 @@
+#!/usr/bin/env ruby
+# vim: set sw=4 sts=4 et tw=80 :
+#
+# Copyright (c) 2007 Richard Brown <mynamewasgone@gmail.com>
+#
+# 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 Paludis
+ class TestCase_DepTag < Test::Unit::TestCase
+ def test_no_create
+ assert_raise NoMethodError do
+ ce = DepTag.new('test')
+ end
+ end
+ end
+
+ class TestCase_DependencyDepTag < Test::Unit::TestCase
+ def get_dt
+ DependencyDepTag.new(PackageDatabaseEntry.new('foo/var','0','moo'))
+ end
+
+ def test_create
+ assert_kind_of DependencyDepTag, get_dt
+ end
+
+ def test_create_error
+ assert_raise ArgumentError do
+ DependencyDepTag.new
+ end
+
+ assert_raise ArgumentError do
+ DependencyDepTag.new('a','b')
+ end
+
+ assert_raise TypeError do
+ DependencyDepTag.new(1)
+ end
+ end
+
+ def test_methods
+ dt = get_dt
+ {:short_text => 'foo/var-0::moo', :category=>'dependency'}.each do |method, val|
+ assert_respond_to dt, method
+ assert_equal val, dt.send(method)
+ end
+ end
+ end
+
+ class TestCase_GLSADepTag < Test::Unit::TestCase
+ def get_dt
+ GLSADepTag.new("id", "title")
+ end
+
+ def test_create
+ assert_kind_of GLSADepTag, get_dt
+ end
+
+ def test_create_error
+ assert_raise ArgumentError do
+ GLSADepTag.new
+ end
+
+ assert_raise ArgumentError do
+ GLSADepTag.new('a')
+ end
+
+ assert_raise TypeError do
+ GLSADepTag.new(1,1)
+ end
+ end
+
+ def test_respond_to
+ dt = get_dt
+ {
+ :short_text => 'GLSA-id',
+ :category=>'glsa',
+ :glsa_title => 'title'
+ }.each do |method, val|
+ assert_respond_to dt, method
+ assert_equal val, dt.send(method)
+ end
+ end
+ end
+
+ class TestCase_GeneralSetDepTag < Test::Unit::TestCase
+ def get_dt
+ GeneralSetDepTag.new("world", "title")
+ end
+
+ def test_create
+ assert_kind_of GeneralSetDepTag, get_dt
+ end
+
+ def test_create_error
+ assert_raise ArgumentError do
+ GeneralSetDepTag.new
+ end
+
+ assert_raise ArgumentError do
+ GeneralSetDepTag.new('a')
+ end
+
+ assert_raise TypeError do
+ GeneralSetDepTag.new(1,1)
+ end
+ end
+
+ def test_respond_to
+ dt = get_dt
+ {
+ :short_text => 'world',
+ :category=>'general',
+ :source => 'title'
+ }.each do |method, val|
+ assert_respond_to dt, method
+ assert_equal val, dt.send(method)
+ end
+ end
+ end
+end
+
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index 1f08745..9404507 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -89,6 +89,7 @@ namespace paludis
VALUE contents_to_value(std::tr1::shared_ptr<const Contents>);
VALUE contents_entry_to_value(std::tr1::shared_ptr<const ContentsEntry>);
VALUE portage_repository_profiles_desc_line_to_value(const PortageRepositoryProfilesDescLine &);
+ VALUE dep_tag_to_value(std::tr1::shared_ptr<const DepTag>);
VersionSpec value_to_version_spec(VALUE v);
std::tr1::shared_ptr<const VersionMetadata> value_to_version_metadata(VALUE);