aboutsummaryrefslogtreecommitdiff
path: root/ruby
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-28 23:44:02 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-04-04 08:32:58 +0100
commitb7f5d7dbfeff2e406ef24ca471657e1735a4db4f (patch)
treec1af04c563afeff3b8410022f1cd9079299dd6ce /ruby
parent968efa61fa4abe5349ffc453ac46087867eaa29b (diff)
downloadpaludis-b7f5d7dbfeff2e406ef24ca471657e1735a4db4f.tar.gz
paludis-b7f5d7dbfeff2e406ef24ca471657e1735a4db4f.tar.xz
Start using constraints for PackageDepSpecs
Diffstat (limited to 'ruby')
-rw-r--r--ruby/Makefile.am1
-rw-r--r--ruby/dep_spec.cc16
-rw-r--r--ruby/dep_spec_TEST.rb10
-rw-r--r--ruby/package_dep_spec_constraint.cc105
-rw-r--r--ruby/paludis_ruby.hh1
5 files changed, 122 insertions, 11 deletions
diff --git a/ruby/Makefile.am b/ruby/Makefile.am
index ade8df5ca..3f46ae03c 100644
--- a/ruby/Makefile.am
+++ b/ruby/Makefile.am
@@ -50,6 +50,7 @@ IF_RUBY_SOURCES = \
metadata_key.cc \
name.cc \
nice_names-nn.hh nice_names-nn.cc \
+ package_dep_spec_constraint.cc \
package_id.cc \
paludis_ruby.cc paludis_ruby.hh \
qualified_package_name.cc \
diff --git a/ruby/dep_spec.cc b/ruby/dep_spec.cc
index 9f6790bc0..b6628e8d7 100644
--- a/ruby/dep_spec.cc
+++ b/ruby/dep_spec.cc
@@ -19,10 +19,13 @@
*/
#include <paludis_ruby.hh>
+
#include <paludis/dep_spec.hh>
#include <paludis/user_dep_spec.hh>
#include <paludis/version_requirements.hh>
#include <paludis/version_operator.hh>
+#include <paludis/package_dep_spec_constraint.hh>
+
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/sequence.hh>
#include <paludis/util/options.hh>
@@ -31,6 +34,7 @@
#include <paludis/util/indirect_iterator-impl.hh>
#include <paludis/util/make_null_shared_ptr.hh>
#include <paludis/util/accept_visitor.hh>
+
#include <algorithm>
#include <list>
#include <ruby.h>
@@ -576,18 +580,18 @@ namespace
/*
* call-seq:
- * package -> QualifiedPackageName or Nil
+ * package_name_constraint -> PackageDepSpecConstraint or Nil
*
- * Fetch the package name.
+ * Fetch the package name constraint (may be Nil).
*/
VALUE
- package_dep_spec_package(VALUE self)
+ package_dep_spec_package_name_constraint(VALUE self)
{
std::shared_ptr<WrappedSpecBase> * ptr;
Data_Get_Struct(self, std::shared_ptr<WrappedSpecBase>, ptr);
- if (! bool(std::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->package_ptr()))
+ if (! bool(std::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->package_name_constraint()))
return Qnil;
- return qualified_package_name_to_value(*std::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->package_ptr());
+ return package_dep_spec_constraint_to_value(std::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->package_name_constraint());
}
/*
@@ -1107,7 +1111,7 @@ namespace
* use Paludis::parse_user_package_dep_spec.
*/
c_package_dep_spec = rb_define_class_under(paludis_module(), "PackageDepSpec", c_string_dep_spec);
- rb_define_method(c_package_dep_spec, "package", RUBY_FUNC_CAST(&package_dep_spec_package), 0);
+ rb_define_method(c_package_dep_spec, "package_name_constraint", RUBY_FUNC_CAST(&package_dep_spec_package_name_constraint), 0);
rb_define_method(c_package_dep_spec, "package_name_part", RUBY_FUNC_CAST(&package_dep_spec_package_name_part), 0);
rb_define_method(c_package_dep_spec, "category_name_part", RUBY_FUNC_CAST(&package_dep_spec_category_name_part), 0);
rb_define_method(c_package_dep_spec, "slot_requirement", RUBY_FUNC_CAST(&package_dep_spec_slot_requirement_ptr), 0);
diff --git a/ruby/dep_spec_TEST.rb b/ruby/dep_spec_TEST.rb
index 2866ee3fa..6c5363f3b 100644
--- a/ruby/dep_spec_TEST.rb
+++ b/ruby/dep_spec_TEST.rb
@@ -140,11 +140,11 @@ module Paludis
end
def test_package
- assert_equal QualifiedPackageName.new("foo/bar"), pda.package
- assert_nil pdb.package
- assert_equal QualifiedPackageName.new("foo/bar"), pdc.package
- assert_nil pdd.package
- assert_equal QualifiedPackageName.new("foo/bar"), pde.package
+ assert_equal QualifiedPackageName.new("foo/bar"), pda.package_name_constraint.name
+ assert_nil pdb.package_name_constraint
+ assert_equal QualifiedPackageName.new("foo/bar"), pdc.package_name_constraint.name
+ assert_nil pdd.package_name_constraint
+ assert_equal QualifiedPackageName.new("foo/bar"), pde.package_name_constraint.name
end
def test_from_repository
diff --git a/ruby/package_dep_spec_constraint.cc b/ruby/package_dep_spec_constraint.cc
new file mode 100644
index 000000000..4cfd42f67
--- /dev/null
+++ b/ruby/package_dep_spec_constraint.cc
@@ -0,0 +1,105 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2011 Ciaran McCreesh
+ *
+ * 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_dep_spec_constraint.hh>
+
+#include <algorithm>
+#include <list>
+#include <ruby.h>
+
+using namespace paludis;
+using namespace paludis::ruby;
+
+namespace
+{
+ static VALUE c_package_dep_spec_constraint;
+ static VALUE c_name_constraint;
+
+ struct V
+ {
+ VALUE value;
+ std::shared_ptr<const PackageDepSpecConstraint> mm;
+
+ V(const std::shared_ptr<const PackageDepSpecConstraint> & m) :
+ mm(m)
+ {
+ }
+
+ void visit(const NameConstraint &)
+ {
+ value = Data_Wrap_Struct(c_name_constraint, 0, &Common<std::shared_ptr<const PackageDepSpecConstraint> >::free,
+ new std::shared_ptr<const PackageDepSpecConstraint>(mm));
+ }
+ };
+
+ /*
+ * Document-method: name
+ *
+ * The name constraint.
+ */
+ static VALUE
+ name_constraint_name(VALUE self)
+ {
+ std::shared_ptr<const PackageDepSpecConstraint> * ptr;
+ Data_Get_Struct(self, std::shared_ptr<const PackageDepSpecConstraint>, ptr);
+ return qualified_package_name_to_value((std::static_pointer_cast<const NameConstraint>(*ptr))->name());
+ }
+
+ void do_register_package_dep_spec_constraint()
+ {
+ /*
+ * Document-class: Paludis::PackageDepSpecConstraint
+ *
+ * Represents a constraint in a PackageDepSpec.
+ */
+ c_package_dep_spec_constraint = rb_define_class_under(paludis_module(), "PackageDepSpecConstraint", rb_cObject);
+ rb_funcall(c_package_dep_spec_constraint, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ /*
+ * Document-class: Paludis::NameConstraint
+ *
+ * Represents a cat/pkg name constraint in a PackageDepSpec.
+ */
+ c_name_constraint = rb_define_class_under(
+ paludis_module(), "NameConstraint", c_package_dep_spec_constraint);
+ rb_funcall(c_name_constraint, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_package_dep_spec_constraint, "name", RUBY_FUNC_CAST(&name_constraint_name), 0);
+ }
+}
+
+VALUE
+paludis::ruby::package_dep_spec_constraint_to_value(const std::shared_ptr<const PackageDepSpecConstraint> & m)
+{
+ try
+ {
+ V v(m);
+ m->accept(v);
+ return v.value;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+}
+
+RegisterRubyClass::Register paludis_ruby_register_package_dep_spec_constraint PALUDIS_ATTRIBUTE((used))
+ (&do_register_package_dep_spec_constraint);
+
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index aab1fb1c4..53d98b490 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -105,6 +105,7 @@ namespace paludis
VALUE choice_value_to_value(const std::shared_ptr<const ChoiceValue> & c);
VALUE match_package_options_to_value(const MatchPackageOptions & c);
VALUE bool_to_value(bool b);
+ VALUE package_dep_spec_constraint_to_value(const std::shared_ptr<const PackageDepSpecConstraint> &);
VersionSpec value_to_version_spec(VALUE v);
std::shared_ptr<const PackageID> value_to_package_id(VALUE, bool nil_ok = false);