aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-12-12 15:48:12 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-12-12 15:48:12 +0000
commiteb72c05d1ad7fd6eb98947ea1520f358f307e8fe (patch)
treedd8d05bfc23f2bac86b034dd53f6547fb7106f4f
parent28197c59b0271b4d5feb84e997c2692021990085 (diff)
downloadpaludis-eb72c05d1ad7fd6eb98947ea1520f358f307e8fe.tar.gz
paludis-eb72c05d1ad7fd6eb98947ea1520f358f307e8fe.tar.xz
(ruby) Add Mask classes and keys.
-rw-r--r--doc/api/index.html.part2
-rw-r--r--doc/api/ruby/Makefile.am1
-rw-r--r--ruby/Makefile.am3
-rw-r--r--ruby/package_id.cc73
-rw-r--r--ruby/package_id_TEST.rb20
-rw-r--r--ruby/paludis_ruby.hh1
6 files changed, 97 insertions, 3 deletions
diff --git a/doc/api/index.html.part b/doc/api/index.html.part
index 42d4375..44fc7ee 100644
--- a/doc/api/index.html.part
+++ b/doc/api/index.html.part
@@ -123,7 +123,7 @@ how concepts map on to different language bindings.</p>
<tr>
<td>example_mask</td>
<td><a href="cplusplus/example__mask_8cc-example.html">C++</a></td>
- <td></td>
+ <td><a href="ruby/example_mask.html">Ruby</a></td>
<td></td>
<td>How to use Mask</td>
</tr>
diff --git a/doc/api/ruby/Makefile.am b/doc/api/ruby/Makefile.am
index f655121..c4826ca 100644
--- a/doc/api/ruby/Makefile.am
+++ b/doc/api/ruby/Makefile.am
@@ -30,6 +30,7 @@ examples = \
example_environment.rb \
example_dep_spec.rb \
example_dep_tree.rb \
+ example_mask.rb \
example_query.rb \
example_version_operator.rb \
example_version_spec.rb
diff --git a/ruby/Makefile.am b/ruby/Makefile.am
index 1afcce6..5a3082a 100644
--- a/ruby/Makefile.am
+++ b/ruby/Makefile.am
@@ -53,7 +53,8 @@ IF_RUBY_SOURCES = \
qualified_package_name.cc \
query.cc \
repository.cc \
- version_spec.cc
+ version_spec.cc \
+ mask.cc
IF_RUBY_QA_SOURCES = \
qa.cc
diff --git a/ruby/package_id.cc b/ruby/package_id.cc
index a0b633b..1243111 100644
--- a/ruby/package_id.cc
+++ b/ruby/package_id.cc
@@ -185,6 +185,74 @@ namespace
}
/*
+ * call-seq:
+ * masks -> Array
+ *
+ * Our masks.
+ */
+ VALUE
+ package_id_masks(VALUE self)
+ {
+ tr1::shared_ptr<const PackageID> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const PackageID>, self_ptr);
+ VALUE result(rb_ary_new());
+ for (PackageID::MasksConstIterator it((*self_ptr)->begin_masks()),
+ it_end((*self_ptr)->end_masks()); it_end != it; ++it)
+ {
+ rb_ary_push(result, mask_to_value(*it));
+ }
+ return result;
+ }
+
+ /*
+ * call-seq:
+ * invalidate_masks -> Qnil
+ *
+ * Invalidate any masks.
+ *
+ * PackageID implementations may cache masks. This can cause problems if the operating environment changes.
+ * Calling this method will clear any masks held by the PackageID.
+ */
+ VALUE
+ package_id_invalidate_masks(VALUE self)
+ {
+ tr1::shared_ptr<const PackageID> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const PackageID>, self_ptr);
+ (*self_ptr)->invalidate_masks();
+ return Qnil;
+ }
+
+ /*
+ * Document-method: masked?
+ *
+ * call-seq:
+ * masked? -> true or false
+ *
+ * Do we have any masks?
+ */
+ /*
+ * Document-method: breaks_portage?
+ *
+ * call-seq:
+ * breaks_portage? -> true or false
+ *
+ * Do we break Portage?
+ *
+ * This method may be used by Environment implementations to apply a "we don't want packages that break Portage" mask.
+ */
+ template <bool (PackageID::* m_) () const>
+ struct PackageIDBool
+ {
+ static VALUE
+ fetch(VALUE self)
+ {
+ tr1::shared_ptr<const PackageID> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const PackageID>, self_ptr);
+ return (self_ptr->get()->*m_)() ? Qtrue : Qfalse;
+ }
+ };
+
+ /*
* Document-method: keywords_key
*
* call-seq:
@@ -367,6 +435,11 @@ namespace
rb_define_method(c_package_id, "perform_action", RUBY_FUNC_CAST(&package_id_perform_action), 1);
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, "masked?", RUBY_FUNC_CAST((&PackageIDBool<&PackageID::masked>::fetch)), 0);
+ rb_define_method(c_package_id, "invalidate_masks", RUBY_FUNC_CAST(&package_id_invalidate_masks), 0);
+ rb_define_method(c_package_id, "breaks_portage?", RUBY_FUNC_CAST((&PackageIDBool<&PackageID::breaks_portage>::fetch)), 0);
+
rb_define_method(c_package_id, "virtual_for_key", RUBY_FUNC_CAST((&KeyValue<MetadataPackageIDKey, &PackageID::virtual_for_key>::fetch)), 0);
rb_define_method(c_package_id, "keywords_key", RUBY_FUNC_CAST((&KeyValue<MetadataCollectionKey<KeywordNameSet>,&PackageID::keywords_key>::fetch)), 0);
rb_define_method(c_package_id, "iuse_key", RUBY_FUNC_CAST((&KeyValue<MetadataCollectionKey<IUseFlagSet>,&PackageID::iuse_key>::fetch)), 0);
diff --git a/ruby/package_id_TEST.rb b/ruby/package_id_TEST.rb
index e076246..be14b38 100644
--- a/ruby/package_id_TEST.rb
+++ b/ruby/package_id_TEST.rb
@@ -109,7 +109,8 @@ module Paludis
:keywords_key => MetadataKeywordNameSetKey, :iuse_key => MetadataIUseFlagSetKey,
:short_description_key => MetadataStringKey, :long_description_key => MetadataStringKey,
:contents_key => MetadataContentsKey, :installed_time_key => MetadataTimeKey,
- :source_origin_key => MetadataStringKey, :binary_origin_key => MetadataStringKey
+ :source_origin_key => MetadataStringKey, :binary_origin_key => MetadataStringKey,
+ :masks => Array
}.each_pair do | method, type |
assert_respond_to pid_testrepo, method
@@ -161,6 +162,23 @@ module Paludis
end
assert keys.empty?
end
+
+ def test_masked?
+ assert pid_testrepo.masked?
+ assert !pid_installed.masked?
+ end
+
+ def test_breaks_portage?
+ assert !pid_testrepo.breaks_portage?
+ end
+
+ def test_masks
+ masks = pid_testrepo.masks
+ assert_equal 1, masks.length
+ mask = masks.first
+ assert_kind_of RepositoryMask, mask
+ assert_equal "repository_mask", mask.mask_key.raw_name
+ end
end
class TestCase_ERepo < Test::Unit::TestCase
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index b54c151..deb30e3 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 mask_to_value(tr1::shared_ptr<const Mask>);
VersionSpec value_to_version_spec(VALUE v);
tr1::shared_ptr<const PackageID> value_to_package_id(VALUE);