aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-06 01:37:53 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-06 01:37:53 +0000
commitb735897c4ebea569a3363b1ffd5a30aa2fa7dd25 (patch)
tree47eee8eb8bdfd350686792901aee89284d13bc2d
parent4a7e31c1a5bcef93417556a39f7c934df79033b2 (diff)
downloadpaludis-b735897c4ebea569a3363b1ffd5a30aa2fa7dd25.tar.gz
paludis-b735897c4ebea569a3363b1ffd5a30aa2fa7dd25.tar.xz
(ruby) Add bindings for URIDepLabel.
-rw-r--r--ruby/dep_spec.cc140
-rw-r--r--ruby/dep_spec_TEST.rb63
-rwxr-xr-xruby/dep_spec_TEST_setup.sh15
-rw-r--r--ruby/metadata_key.cc22
-rw-r--r--ruby/package_id_TEST.rb4
-rw-r--r--ruby/paludis_ruby.hh1
6 files changed, 243 insertions, 2 deletions
diff --git a/ruby/dep_spec.cc b/ruby/dep_spec.cc
index 2528514..7771881 100644
--- a/ruby/dep_spec.cc
+++ b/ruby/dep_spec.cc
@@ -57,6 +57,14 @@ namespace
static VALUE c_version_requirements_mode;
+ static VALUE c_uri_label;
+ static VALUE c_uri_mirrors_then_listed_label;
+ static VALUE c_uri_mirrors_only_label;
+ static VALUE c_uri_listed_only_label;
+ static VALUE c_uri_listed_then_mirrors_label;
+ static VALUE c_uri_local_mirrors_only_label;
+ static VALUE c_uri_manual_only_label;
+
struct WrappedSpecBase;
template <typename> struct WrappedSpec;
@@ -270,6 +278,33 @@ namespace
}
VALUE
+ uri_labels_dep_spec_labels(VALUE self)
+ {
+ tr1::shared_ptr<const WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const WrappedSpecBase>, ptr);
+ tr1::shared_ptr<const URILabelsDepSpec> real_ptr(tr1::static_pointer_cast<const WrappedSpec<URILabelsDepSpec> >(*ptr)->spec());
+
+ if (rb_block_given_p())
+ {
+ for (URILabelsDepSpec::ConstIterator it(real_ptr->begin()),
+ it_end(real_ptr->end()); it_end != it; ++it)
+ rb_yield(uri_label_to_value(*it));
+
+ return Qnil;
+ }
+ else
+ {
+ VALUE result(rb_ary_new());
+
+ for (URILabelsDepSpec::ConstIterator it(real_ptr->begin()),
+ it_end(real_ptr->end()); it_end != it; ++it)
+ rb_ary_push(result, uri_label_to_value(*it));
+
+ return result;
+ }
+ }
+
+ VALUE
block_dep_spec_new(VALUE self, VALUE spec)
{
tr1::shared_ptr<const WrappedSpecBase> * ptr(0);
@@ -671,6 +706,78 @@ namespace
}
+ struct URILabelToValue :
+ ConstVisitor<URILabelVisitorTypes>
+ {
+ VALUE value;
+ tr1::shared_ptr<const URILabel> mm;
+
+ URILabelToValue(const tr1::shared_ptr<const URILabel> & _m) :
+ mm(_m)
+ {
+ }
+
+ void visit(const URIMirrorsThenListedLabel &)
+ {
+ value = Data_Wrap_Struct(c_uri_mirrors_then_listed_label, 0, &Common<tr1::shared_ptr<const URILabel> >::free,
+ new tr1::shared_ptr<const URILabel>(mm));
+ }
+
+ void visit(const URIMirrorsOnlyLabel &)
+ {
+ value = Data_Wrap_Struct(c_uri_mirrors_only_label, 0, &Common<tr1::shared_ptr<const URILabel> >::free,
+ new tr1::shared_ptr<const URILabel>(mm));
+ }
+
+ void visit(const URIListedOnlyLabel &)
+ {
+ value = Data_Wrap_Struct(c_uri_listed_only_label, 0, &Common<tr1::shared_ptr<const URILabel> >::free,
+ new tr1::shared_ptr<const URILabel>(mm));
+ }
+
+ void visit(const URIListedThenMirrorsLabel &)
+ {
+ value = Data_Wrap_Struct(c_uri_listed_then_mirrors_label, 0, &Common<tr1::shared_ptr<const URILabel> >::free,
+ new tr1::shared_ptr<const URILabel>(mm));
+ }
+
+ void visit(const URILocalMirrorsOnlyLabel &)
+ {
+ value = Data_Wrap_Struct(c_uri_local_mirrors_only_label, 0, &Common<tr1::shared_ptr<const URILabel> >::free,
+ new tr1::shared_ptr<const URILabel>(mm));
+ }
+
+ void visit(const URIManualOnlyLabel &)
+ {
+ value = Data_Wrap_Struct(c_uri_manual_only_label, 0, &Common<tr1::shared_ptr<const URILabel> >::free,
+ new tr1::shared_ptr<const URILabel>(mm));
+ }
+ };
+
+ /*
+ * Document-method: text
+ *
+ * call-seq:
+ * text -> String
+ *
+ * Our text.
+ */
+ /*
+ * Document-method: to_s
+ *
+ * call-seq:
+ * to_s -> String
+ *
+ * Fetch a string representation of ourself.
+ */
+ VALUE
+ uri_label_text(VALUE self)
+ {
+ tr1::shared_ptr<const URILabel> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const URILabel>, ptr);
+ return rb_str_new2((*ptr)->text().c_str());
+ }
+
void do_register_dep_spec()
{
/*
@@ -828,6 +935,7 @@ namespace
rb_define_method(c_uri_labels_dep_spec, "initialize", RUBY_FUNC_CAST(&dep_spec_init_0), 0);
VALUE (* uri_labels_dep_spec_to_s) (VALUE) = &dep_spec_to_s<URILabelsDepSpec>;
rb_define_method(c_uri_labels_dep_spec, "to_s", RUBY_FUNC_CAST(uri_labels_dep_spec_to_s), 0);
+ rb_define_method(c_uri_labels_dep_spec, "labels", RUBY_FUNC_CAST(&uri_labels_dep_spec_labels), 0);
/*
* Document-class: Paludis::BlockDepSpec
@@ -843,6 +951,23 @@ namespace
rb_define_method(c_block_dep_spec, "to_s", RUBY_FUNC_CAST(block_dep_spec_to_s), 0);
/*
+ * Document-class: Paludis::URILabel
+ *
+ * URI label base class.
+ */
+ c_uri_label = rb_define_class_under(paludis_module(), "URILabel", rb_cObject);
+ rb_funcall(c_uri_label, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_uri_label, "text", RUBY_FUNC_CAST(&uri_label_text), 0);
+ rb_define_method(c_uri_label, "to_s", RUBY_FUNC_CAST(&uri_label_text), 0);
+
+ c_uri_mirrors_then_listed_label = rb_define_class_under(paludis_module(), "URIMirrorsThenListedLabel", c_uri_label);
+ c_uri_mirrors_only_label = rb_define_class_under(paludis_module(), "URIMirrorsOnlyLabel", c_uri_label);
+ c_uri_listed_only_label = rb_define_class_under(paludis_module(), "URIListedOnlyLabel", c_uri_label);
+ c_uri_listed_then_mirrors_label = rb_define_class_under(paludis_module(), "URIListedThenMirrorsLabel", c_uri_label);
+ c_uri_local_mirrors_only_label = rb_define_class_under(paludis_module(), "URILocalMirrorsOnlyLabel", c_uri_label);
+ c_uri_manual_only_label = rb_define_class_under(paludis_module(), "URIManualOnlyLabel", c_uri_label);
+
+ /*
* Document-module: Paludis::VersionRequirementsMode
*
* What sort of VersionRequirements to we have.
@@ -913,6 +1038,21 @@ paludis::ruby::dep_tree_to_value(const tr1::shared_ptr<const typename T_::ConstI
}
}
+VALUE
+paludis::ruby::uri_label_to_value(const tr1::shared_ptr<const URILabel> & m)
+{
+ try
+ {
+ URILabelToValue v(m);
+ m->accept(v);
+ return v.value;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+}
+
template VALUE dep_tree_to_value <SetSpecTree> (const tr1::shared_ptr<const SetSpecTree::ConstItem> &);
template VALUE dep_tree_to_value <DependencySpecTree> (const tr1::shared_ptr<const DependencySpecTree::ConstItem> &);
template VALUE dep_tree_to_value <FetchableURISpecTree> (const tr1::shared_ptr<const FetchableURISpecTree::ConstItem> &);
diff --git a/ruby/dep_spec_TEST.rb b/ruby/dep_spec_TEST.rb
index 15d12a2..d81a014 100644
--- a/ruby/dep_spec_TEST.rb
+++ b/ruby/dep_spec_TEST.rb
@@ -187,7 +187,7 @@ module Paludis
end
def test_composites
- spec = env.package_database.query(Query::All.new, QueryOrder::RequireExactlyOne).last.build_dependencies_key.value
+ spec = env.package_database.query(Query::Package.new("foo/bar"), QueryOrder::RequireExactlyOne).last.build_dependencies_key.value
assert_kind_of AllDepSpec, spec
assert_equal 2, spec.to_a.length
@@ -222,5 +222,66 @@ module Paludis
end
end
end
+
+ class TestCase_URILabels < Test::Unit::TestCase
+ def env
+ @env or @env = EnvironmentMaker.instance.make_from_spec("")
+ end
+
+ def spec_key
+ env.package_database.query(Query::Package.new("bar/foo"), QueryOrder::RequireExactlyOne).last.fetches_key
+ end
+
+ def test_no_create
+ assert_raise NoMethodError do URILabel.new end
+ [URILabel, URIMirrorsThenListedLabel, URIMirrorsOnlyLabel,
+ URIListedOnlyLabel, URIListedThenMirrorsLabel,
+ URILocalMirrorsOnlyLabel, URIManualOnlyLabel].each do | c |
+ assert_raise NoMethodError do c.new end
+ end
+ end
+
+ def test_initial_label
+ assert_kind_of URIListedThenMirrorsLabel, spec_key.initial_label
+ assert_equal "default", spec_key.initial_label.text
+ assert_equal "default", spec_key.initial_label.to_s
+ end
+
+ def test_uri_labels_dep_spec
+ specs = spec_key.value.to_a
+ assert_equal 6, specs.length
+
+ specs.each do | spec |
+ assert_kind_of URILabelsDepSpec, spec
+ assert_kind_of Array, spec.labels
+
+ array_from_block = []
+ spec.labels { | label | array_from_block << label }
+
+ [spec.labels, array_from_block].each do | array |
+ assert_equal 1, array.length
+ assert_kind_of URILabel, array[0]
+ assert_equal array[0].text, array[0].to_s
+ end
+
+ assert_equal spec.labels[0].class, array_from_block[0].class
+ assert_equal spec.labels[0].text, array_from_block[0].text
+ end
+
+ assert_kind_of URIMirrorsThenListedLabel, specs.to_a[0].labels[0]
+ assert_kind_of URIMirrorsOnlyLabel, specs.to_a[1].labels[0]
+ assert_kind_of URIListedOnlyLabel, specs.to_a[2].labels[0]
+ assert_kind_of URIListedThenMirrorsLabel, specs.to_a[3].labels[0]
+ assert_kind_of URILocalMirrorsOnlyLabel, specs.to_a[4].labels[0]
+ assert_kind_of URIManualOnlyLabel, specs.to_a[5].labels[0]
+
+ assert_equal "mirrors-first", specs.to_a[0].labels[0].text
+ assert_equal "mirrors-only", specs.to_a[1].labels[0].text
+ assert_equal "listed-only", specs.to_a[2].labels[0].text
+ assert_equal "listed-first", specs.to_a[3].labels[0].text
+ assert_equal "local-only", specs.to_a[4].labels[0].text
+ assert_equal "manual", specs.to_a[5].labels[0].text
+ end
+ end
end
diff --git a/ruby/dep_spec_TEST_setup.sh b/ruby/dep_spec_TEST_setup.sh
index fc1ed59..02d2b3a 100755
--- a/ruby/dep_spec_TEST_setup.sh
+++ b/ruby/dep_spec_TEST_setup.sh
@@ -14,11 +14,12 @@ cache = /var/empty
profiles = \${location}/profiles/testprofile
END
-mkdir -p testrepo/{eclass,distfiles,profiles/testprofile,foo/bar/files} || exit 1
+mkdir -p testrepo/{eclass,distfiles,profiles/testprofile,foo/bar/files,bar/foo/files} || exit 1
cd testrepo || exit 1
echo "testrepo" > profiles/repo_name || exit 1
cat <<END > profiles/categories || exit 1
foo
+bar
END
cat <<END > profiles/testprofile/make.defaults
ARCH=test
@@ -40,3 +41,15 @@ KEYWORDS="test"
DEPEND="|| ( foo/bar foo/baz ) foo/monkey"
END
+cat <<"END" > bar/foo/foo-1.0.ebuild || exit 1
+EAPI="exheres-0"
+DESCRIPTION="Test package"
+HOMEPAGE="http://paludis.pioto.org/"
+SRC_URI="mirrors-first: mirrors-only: listed-only: listed-first: local-only: manual: "
+SLOT="0"
+MYOPTIONS=""
+LICENSE="GPL-2"
+PLATFORMS="test"
+DEPENDENCIES=""
+END
+
diff --git a/ruby/metadata_key.cc b/ruby/metadata_key.cc
index fe76e91..cdc4c48 100644
--- a/ruby/metadata_key.cc
+++ b/ruby/metadata_key.cc
@@ -419,6 +419,27 @@ namespace
}
};
+ /*
+ * call-seq:
+ * initial_label -> URILabel
+ *
+ * Return the initial label to use when deciding the behaviour of
+ * individual items in the heirarchy.
+ */
+ VALUE
+ metadata_fetchable_uri_spec_tree_key_initial_label(VALUE self)
+ {
+ try
+ {
+ tr1::shared_ptr<const MetadataKey> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
+ return uri_label_to_value((tr1::static_pointer_cast<const MetadataSpecTreeKey<FetchableURISpecTree> >(*self_ptr))->initial_label());
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
VALUE
repository_mask_info_mask_file(VALUE self)
@@ -596,6 +617,7 @@ namespace
*/
c_metadata_fetchable_uri_spec_tree_key = rb_define_class_under(paludis_module(), "MetadataFetchableURISpecTreeKey", c_metadata_key);
rb_define_method(c_metadata_fetchable_uri_spec_tree_key, "value", RUBY_FUNC_CAST((&SpecTreeValue<FetchableURISpecTree>::fetch)), 0);
+ rb_define_method(c_metadata_fetchable_uri_spec_tree_key, "initial_label", RUBY_FUNC_CAST(&metadata_fetchable_uri_spec_tree_key_initial_label), 0);
/*
* Document-class: Paludis::MetadataSimpleURISpecTreeKey
diff --git a/ruby/package_id_TEST.rb b/ruby/package_id_TEST.rb
index 832f8dc..4c409b3 100644
--- a/ruby/package_id_TEST.rb
+++ b/ruby/package_id_TEST.rb
@@ -270,6 +270,10 @@ module Paludis
def test_fetches_key
assert_kind_of MetadataFetchableURISpecTreeKey, pid_testrepo.fetches_key
assert_kind_of AllDepSpec, pid_testrepo.fetches_key.value
+ assert_respond_to pid_testrepo.fetches_key, :initial_label
+ assert_kind_of URILabel, pid_testrepo.fetches_key.initial_label
+ assert_kind_of URIMirrorsThenListedLabel, pid_testrepo.fetches_key.initial_label
+ assert_equal "default", pid_testrepo.fetches_key.initial_label.text
end
end
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index deb30e3..be165ac 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -89,6 +89,7 @@ namespace paludis
#endif
template <typename T_> VALUE dep_tree_to_value(const tr1::shared_ptr<const typename T_::ConstItem> &);
VALUE package_dep_spec_to_value(const tr1::shared_ptr<const PackageDepSpec> &);
+ VALUE uri_label_to_value(const tr1::shared_ptr<const URILabel> &);
VALUE mask_to_value(tr1::shared_ptr<const Mask>);
VersionSpec value_to_version_spec(VALUE v);