aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2011-03-20 02:56:38 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2011-03-20 02:56:47 +0000
commitf2d92c9ef1a5bbe09df3d1ff1489dbe07c61c841 (patch)
tree5f971e343820505fff61a1306fce731f44d8dc9d
parentf979d1f1e5393014b7fbd52a2c50abcd5f9089cd (diff)
downloadpaludis-f2d92c9ef1a5bbe09df3d1ff1489dbe07c61c841.tar.gz
paludis-f2d92c9ef1a5bbe09df3d1ff1489dbe07c61c841.tar.xz
(ruby) Add bindings for overridden masks
-rw-r--r--ruby/mask.cc54
-rw-r--r--ruby/package_id.cc30
-rw-r--r--ruby/package_id_TEST.rb15
-rwxr-xr-xruby/package_id_TEST_setup.sh2
-rw-r--r--ruby/paludis_ruby.hh1
5 files changed, 98 insertions, 4 deletions
diff --git a/ruby/mask.cc b/ruby/mask.cc
index 93ca902..95b2a1a 100644
--- a/ruby/mask.cc
+++ b/ruby/mask.cc
@@ -33,6 +33,8 @@ namespace
static VALUE c_repository_mask;
static VALUE c_unsupported_mask;
static VALUE c_association_mask;
+ static VALUE c_overridden_mask;
+ static VALUE c_mask_override_reason;
struct V
{
@@ -170,6 +172,30 @@ namespace
return package_dep_spec_to_value((cast_ptr)->associated_package_spec());
}
+ /*
+ * call-seq:
+ * mask -> Mask
+ */
+ VALUE
+ overridden_mask_mask(VALUE self)
+ {
+ std::shared_ptr<const OverriddenMask> * ptr;
+ Data_Get_Struct(self, std::shared_ptr<const OverriddenMask>, ptr);
+ return mask_to_value((*ptr)->mask());
+ }
+
+ /*
+ * call-seq:
+ * override_reason -> MaskOverrideReason
+ */
+ VALUE
+ overridden_mask_override_reason(VALUE self)
+ {
+ std::shared_ptr<const OverriddenMask> * ptr;
+ Data_Get_Struct(self, std::shared_ptr<const OverriddenMask>, ptr);
+ return INT2FIX((*ptr)->override_reason());
+ }
+
void do_register_mask()
{
@@ -237,6 +263,27 @@ namespace
*/
c_association_mask = rb_define_class_under(paludis_module(), "AssociationMask", c_mask);
rb_define_method(c_association_mask, "associated_package_spec", RUBY_FUNC_CAST(&association_mask_associated_package), 0);
+
+ /*
+ * Document-class: Paludis::OverriddenMask
+ *
+ * An OverriddenMask holds a Mask and an explanation of why it has been overridden.
+ */
+ c_overridden_mask = rb_define_class_under(paludis_module(), "OverriddenMask", rb_cObject);
+ rb_define_method(c_overridden_mask, "mask", RUBY_FUNC_CAST(&overridden_mask_mask), 0);
+ rb_define_method(c_overridden_mask, "override_reason", RUBY_FUNC_CAST(&overridden_mask_override_reason), 0);
+
+ /*
+ * Document-module: Paludis::MaskOverrideReason
+ *
+ * The reason an OverriddenMask is overridden.
+ */
+ c_mask_override_reason = rb_define_module_under(paludis_module(), "MaskOverrideReason");
+ for (MaskOverrideReason r(static_cast<MaskOverrideReason>(0)), r_end(last_mro) ; r != r_end ;
+ r = static_cast<MaskOverrideReason>(static_cast<int>(r) + 1))
+ rb_define_const(c_mask_override_reason, value_case_to_RubyCase(stringify(r)).c_str(), INT2FIX(r));
+
+ // cc_enum_special<paludis/mask.hh, MaskOverrideReason, c_mask_override_reason>
}
}
@@ -255,6 +302,13 @@ paludis::ruby::mask_to_value(std::shared_ptr<const Mask> m)
}
}
+VALUE
+paludis::ruby::overridden_mask_to_value(std::shared_ptr<const OverriddenMask> m)
+{
+ return Data_Wrap_Struct(c_overridden_mask, 0, &Common<std::shared_ptr<const OverriddenMask> >::free,
+ new std::shared_ptr<const OverriddenMask>(m));
+}
+
RegisterRubyClass::Register paludis_ruby_register_mask PALUDIS_ATTRIBUTE((used))
(&do_register_mask);
diff --git a/ruby/package_id.cc b/ruby/package_id.cc
index 16b048e..a52a7aa 100644
--- a/ruby/package_id.cc
+++ b/ruby/package_id.cc
@@ -261,6 +261,35 @@ namespace
/*
* call-seq:
+ * overridden_masks -> Array
+ *
+ * Our overridden masks.
+ */
+ VALUE
+ package_id_overridden_masks(VALUE self)
+ {
+ std::shared_ptr<const PackageID> * self_ptr;
+ Data_Get_Struct(self, std::shared_ptr<const PackageID>, self_ptr);
+ VALUE result(rb_ary_new());
+ try
+ {
+ for (PackageID::OverriddenMasksConstIterator it((*self_ptr)->begin_overridden_masks()),
+ it_end((*self_ptr)->end_overridden_masks()); it_end != it; ++it)
+ {
+ rb_ary_push(result, overridden_mask_to_value(*it));
+ }
+ return result;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+
+ return Qnil;
+ }
+
+ /*
+ * call-seq:
* breaks_portage -> [:reason, :reason, ...]
*
* Do we break Portage, and if so, why?
@@ -488,6 +517,7 @@ namespace
rb_define_method(c_package_id, "each_metadata", RUBY_FUNC_CAST(&package_id_each_metadata), 0);
rb_define_method(c_package_id, "masks", RUBY_FUNC_CAST(&package_id_masks), 0);
+ rb_define_method(c_package_id, "overridden_masks", RUBY_FUNC_CAST(&package_id_overridden_masks), 0);
rb_define_method(c_package_id, "masked?", RUBY_FUNC_CAST((&PackageIDBool<&PackageID::masked>::fetch)), 0);
rb_define_method(c_package_id, "breaks_portage", RUBY_FUNC_CAST(&package_id_breaks_portage), 0);
diff --git a/ruby/package_id_TEST.rb b/ruby/package_id_TEST.rb
index 45503e8..1f0a181 100644
--- a/ruby/package_id_TEST.rb
+++ b/ruby/package_id_TEST.rb
@@ -27,7 +27,7 @@ module Paludis
module TestStuff
def env
unless @env
- @env = NoConfigEnvironment.new("package_id_TEST_dir/testrepo/", '/var/empty')
+ @env = EnvironmentFactory.instance.create("no-config:repository-dir=package_id_TEST_dir/testrepo/:write-cache=/var/empty:accept-unstable=true")
end
@env
end
@@ -113,7 +113,7 @@ module Paludis
:keywords_key => MetadataKeywordNameSetKey, :choices_key => MetadataChoicesKey,
:short_description_key => MetadataStringKey, :long_description_key => MetadataStringKey,
:contents_key => MetadataContentsKey, :installed_time_key => MetadataTimeKey,
- :from_repositories_key => Array, :masks => Array
+ :from_repositories_key => Array, :masks => Array, :overridden_masks => Array
}.each_pair do | method, type |
assert_respond_to pid_testrepo, method
@@ -183,6 +183,15 @@ module Paludis
assert_kind_of RepositoryMask, mask
end
+ def test_overridden_masks
+ masks = pid_testrepo.overridden_masks
+ assert_equal 1, masks.length
+ mask = masks.first
+ assert_kind_of OverriddenMask, mask
+ assert_kind_of UnacceptedMask, mask.mask
+ assert_equal MaskOverrideReason::AcceptedUnstable, mask.override_reason
+ end
+
def test_hash
a = pid_testrepo
b = pid_testrepo
@@ -239,7 +248,7 @@ module Paludis
def test_keywords_key
assert_kind_of MetadataKeywordNameSetKey, pid_testrepo.keywords_key
assert_kind_of Array, pid_testrepo.keywords_key.value
- assert_equal ['test'], pid_testrepo.keywords_key.value
+ assert_equal ['~test'], pid_testrepo.keywords_key.value
end
def test_build_dependencies_key
diff --git a/ruby/package_id_TEST_setup.sh b/ruby/package_id_TEST_setup.sh
index 6b71c1c..ed1668b 100755
--- a/ruby/package_id_TEST_setup.sh
+++ b/ruby/package_id_TEST_setup.sh
@@ -32,7 +32,7 @@ SRC_URI="http://example.com/${P}.tar.bz2"
SLOT="0"
IUSE="testflag"
LICENSE="GPL-2"
-KEYWORDS="test"
+KEYWORDS="~test"
RESTRICT="monkey"
DEPEND="foo/bar"
RDEPEND=""
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index b8d3a94..7e2b616 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -100,6 +100,7 @@ namespace paludis
VALUE uri_label_to_value(const std::shared_ptr<const URILabel> &);
VALUE dependencies_label_to_value(const std::shared_ptr<const DependenciesLabel> &);
VALUE mask_to_value(std::shared_ptr<const Mask>);
+ VALUE overridden_mask_to_value(std::shared_ptr<const OverriddenMask>);
VALUE choices_to_value(const std::shared_ptr<const Choices> & c);
VALUE choice_to_value(const std::shared_ptr<const Choice> & c);
VALUE choice_value_to_value(const std::shared_ptr<const ChoiceValue> & c);