aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2006-12-13 19:40:53 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2006-12-13 19:40:53 +0000
commit1afdc1a1bc9073be5f7b690b2591f88582032b36 (patch)
treec4abde5cad0e5acdda2bcbce134291772ebdca22
parent2ae07833255d715d323e4d0bfd352806c83898ea (diff)
downloadpaludis-1afdc1a1bc9073be5f7b690b2591f88582032b36.tar.gz
paludis-1afdc1a1bc9073be5f7b690b2591f88582032b36.tar.xz
Improve ruby binding.
-rw-r--r--ruby/dep_atom.cc27
-rw-r--r--ruby/dep_atom_TEST.rb7
-rw-r--r--ruby/version_metadata.cc140
-rw-r--r--ruby/version_spec.cc26
-rw-r--r--ruby/version_spec_TEST.rb13
5 files changed, 203 insertions, 10 deletions
diff --git a/ruby/dep_atom.cc b/ruby/dep_atom.cc
index 5c8950f..a1363e4 100644
--- a/ruby/dep_atom.cc
+++ b/ruby/dep_atom.cc
@@ -233,6 +233,32 @@ namespace
return rb_str_new2(stringify((*(*ptr)->repository_ptr())).c_str());
}
+ /*
+ * call-seq:
+ * version_requirements -> Array
+ *
+ * Fetch the version requirements. E.g. [ {:operator => '=', :spec => VersionSpec.new('0.1') } ]
+ */
+ VALUE
+ package_dep_atom_version_requirements_ptr(VALUE self) {
+ PackageDepAtom::ConstPointer * ptr;
+ Data_Get_Struct(self, PackageDepAtom::ConstPointer, ptr);
+ VALUE result(rb_ary_new());
+ VALUE result_hash;
+ if ((*ptr)->version_requirements_ptr())
+ for (VersionRequirements::Iterator i((*ptr)->version_requirements_ptr()->begin()),
+ i_end((*ptr)->version_requirements_ptr()->end()) ; i != i_end; ++i)
+ {
+ result_hash = rb_hash_new();
+ rb_hash_aset(result_hash, ID2SYM(rb_intern("operator")),
+ rb_str_new2(stringify(i->version_operator).c_str()));
+ rb_hash_aset(result_hash, ID2SYM(rb_intern("spec")),
+ version_spec_to_value(i->version_spec));
+ rb_ary_push(result, result_hash);
+ }
+ return result;
+ }
+
void do_register_dep_atom()
{
/*
@@ -301,6 +327,7 @@ namespace
rb_define_method(c_package_dep_atom, "text", RUBY_FUNC_CAST(&package_dep_atom_text), 0);
rb_define_method(c_package_dep_atom, "slot", RUBY_FUNC_CAST(&package_dep_atom_slot_ptr), 0);
rb_define_method(c_package_dep_atom, "repository", RUBY_FUNC_CAST(&package_dep_atom_repository_ptr), 0);
+ rb_define_method(c_package_dep_atom, "version_requirements", RUBY_FUNC_CAST(&package_dep_atom_version_requirements_ptr), 0);
/*
* Document-class: Paludis::PlainTextDepAtom
diff --git a/ruby/dep_atom_TEST.rb b/ruby/dep_atom_TEST.rb
index 6200b31..e87a722 100644
--- a/ruby/dep_atom_TEST.rb
+++ b/ruby/dep_atom_TEST.rb
@@ -76,6 +76,13 @@ module Paludis
def test_repository
assert_equal "testrepo", pda.repository
end
+
+ def test_version_requirements
+ assert_kind_of Array, pda.version_requirements
+ assert_equal 1, pda.version_requirements.size
+ assert_equal VersionSpec.new('1'), pda.version_requirements.first[:spec]
+ assert_equal ">=", pda.version_requirements.first[:operator]
+ end
end
class TestCase_PlainTextDepAtom < Test::Unit::TestCase
diff --git a/ruby/version_metadata.cc b/ruby/version_metadata.cc
index 751c5ef..de14cc3 100644
--- a/ruby/version_metadata.cc
+++ b/ruby/version_metadata.cc
@@ -175,14 +175,6 @@ namespace
* Fetches the package restrict_string, if get_ebuild_interface is not Nil.
*/
/*
- * Document-method: keywords
- *
- * call-seq:
- * keywords
- *
- * Fetches the package keywords, if get_ebuild_interface is not Nil.
- */
- /*
* Document-method: eclass_keywords
*
* call-seq:
@@ -222,6 +214,68 @@ namespace
};
/*
+ * Document-method: bin_uri
+ *
+ * call-seq:
+ * bin_uri -> String
+ *
+ * Fetches the package bin_uri, if get_ebin_interface is not Nil
+ */
+ /*
+ * Document-method: src_repository
+ *
+ * call-seq:
+ * src_repository -> String
+ *
+ * Fetches the package src_repository, if get_ebin_interface is not Nil
+ */
+ template <typename T_, T_ EbinVersionMetadata::* m_>
+ struct EbinValue
+ {
+ static VALUE
+ fetch(VALUE self)
+ {
+ VersionMetadata::ConstPointer * self_ptr;
+ Data_Get_Struct(self, VersionMetadata::ConstPointer, self_ptr);
+ if ((*self_ptr)->get_ebin_interface())
+ return rb_str_new2(stringify((*self_ptr)->get_ebin_interface()->*m_).c_str());
+ else
+ return Qnil;
+ }
+ };
+
+ /*
+ * Document-method: package
+ *
+ * call-seq:
+ * package -> String
+ *
+ * Fetches the package name, if get_cran_interface is not Nil
+ */
+ /*
+ * Document-method: version
+ *
+ * call-seq:
+ * version -> String
+ *
+ * Fetches the package version, if get_ebin_interface is not Nil
+ */
+ template <typename T_, T_ CRANVersionMetadata::* m_>
+ struct CRANValue
+ {
+ static VALUE
+ fetch(VALUE self)
+ {
+ VersionMetadata::ConstPointer * self_ptr;
+ Data_Get_Struct(self, VersionMetadata::ConstPointer, self_ptr);
+ if ((*self_ptr)->get_cran_interface())
+ return rb_str_new2(stringify((*self_ptr)->get_cran_interface()->*m_).c_str());
+ else
+ return Qnil;
+ }
+ };
+
+ /*
* Document-method: build_depend
*
* call-seq:
@@ -320,6 +374,58 @@ namespace
}
};
+ /*
+ * call-seq:
+ * virtual_for -> PackageDatabaseEntry
+ *
+ * Fetch package we are a virtual for, if get_virtual_interface is not Nil.
+ */
+ VALUE version_metadata_virtual_for(VALUE self)
+ {
+ VersionMetadata::ConstPointer * self_ptr;
+ Data_Get_Struct(self, VersionMetadata::ConstPointer, self_ptr);
+ if ((*self_ptr)->get_virtual_interface())
+ return package_database_entry_to_value((*self_ptr)->get_virtual_interface()->virtual_for);
+ else
+ return Qnil;
+
+ }
+
+ /*
+ * call-seq:
+ * is_bundle? -> true or false
+ *
+ * Are we a bundle? True or false, if get_virtual_interface is not Nil.
+ */
+ VALUE version_metadata_is_bundle(VALUE self)
+ {
+ VersionMetadata::ConstPointer * self_ptr;
+ Data_Get_Struct(self, VersionMetadata::ConstPointer, self_ptr);
+ if ((*self_ptr)->get_cran_interface())
+ return ((*self_ptr)->get_cran_interface()->is_bundle) ? Qtrue : Qfalse;
+ else
+ return Qnil;
+
+ }
+
+ /*
+ * call-seq:
+ * keywords -> String
+ *
+ * Fetches the package keywords, if get_ebuild_interface or get_cran_interface is not Nil.
+ */
+ VALUE version_metadata_keywords(VALUE self)
+ {
+ VersionMetadata::ConstPointer * self_ptr;
+ Data_Get_Struct(self, VersionMetadata::ConstPointer, self_ptr);
+ if ((*self_ptr)->get_ebuild_interface())
+ return rb_str_new2(((*self_ptr)->get_ebuild_interface()->keywords).c_str());
+ if ((*self_ptr)->get_cran_interface())
+ return rb_str_new2(((*self_ptr)->get_cran_interface()->keywords).c_str());
+ else
+ return Qnil;
+ }
+
void do_register_version_metadata()
{
/*
@@ -350,8 +456,6 @@ namespace
&EbuildVersionMetadata::src_uri>::fetch)), 0);
rb_define_method(c_version_metadata, "restrict_string", RUBY_FUNC_CAST((&EbuildValue<std::string,
&EbuildVersionMetadata::restrict_string>::fetch)), 0);
- rb_define_method(c_version_metadata, "keywords", RUBY_FUNC_CAST((&EbuildValue<std::string,
- &EbuildVersionMetadata::keywords>::fetch)), 0);
rb_define_method(c_version_metadata, "eclass_keywords", RUBY_FUNC_CAST((&EbuildValue<std::string,
&EbuildVersionMetadata::eclass_keywords>::fetch)), 0);
rb_define_method(c_version_metadata, "iuse", RUBY_FUNC_CAST((&EbuildValue<std::string,
@@ -377,6 +481,22 @@ namespace
&VersionMetadataOrigins::source>::fetch)), 0);
rb_define_method(c_version_metadata, "origin_binary", RUBY_FUNC_CAST((&VMOrigins<
&VersionMetadataOrigins::binary>::fetch)), 0);
+
+ rb_define_method(c_version_metadata, "virtual_for", RUBY_FUNC_CAST(&version_metadata_virtual_for), 0);
+
+ rb_define_method(c_version_metadata, "bin_uri", RUBY_FUNC_CAST((&EbinValue<std::string,
+ &EbinVersionMetadata::bin_uri>::fetch)), 0);
+ rb_define_method(c_version_metadata, "src_repository", RUBY_FUNC_CAST((&EbinValue<RepositoryName,
+ &EbinVersionMetadata::src_repository>::fetch)), 0);
+
+ rb_define_method(c_version_metadata, "package", RUBY_FUNC_CAST((&CRANValue<std::string,
+ &CRANVersionMetadata::package>::fetch)), 0);
+ rb_define_method(c_version_metadata, "version", RUBY_FUNC_CAST((&CRANValue<std::string,
+ &CRANVersionMetadata::version>::fetch)), 0);
+ rb_define_method(c_version_metadata, "is_bundle?", RUBY_FUNC_CAST(&version_metadata_is_bundle), 0);
+
+ rb_define_method(c_version_metadata, "keywords", RUBY_FUNC_CAST(&version_metadata_keywords), 0);
+
}
}
diff --git a/ruby/version_spec.cc b/ruby/version_spec.cc
index b233f46..cc28edc 100644
--- a/ruby/version_spec.cc
+++ b/ruby/version_spec.cc
@@ -92,6 +92,30 @@ namespace
}
}
+ /*
+ * call-seq:
+ * bump -> VersionSpec
+ *
+ * This is used by the ~> operator. It returns a VersionSpec where the next to last number is one greater (e.g. 5.3.1 => 5.4).
+ * Any non number parts are stripped (e.g. 1.2.3_alpha4-r5 => 1.3).
+ */
+ VALUE
+ version_spec_bump(VALUE self)
+ {
+ return version_spec_to_value(value_to_version_spec(self).bump());
+ }
+
+ /*
+ * call-seq:
+ * is_scm? -> true or false
+ *
+ * Are we an -scm package, or something pretending to be one?
+ */
+ VALUE version_spec_is_scm(VALUE self)
+ {
+ return value_to_version_spec(self).is_scm() ? Qtrue : Qfalse;
+ }
+
void do_register_version_spec()
{
/*
@@ -108,6 +132,8 @@ namespace
rb_define_method(c_version_spec, "to_s", RUBY_FUNC_CAST(&Common<VersionSpec>::to_s), 0);
rb_define_method(c_version_spec, "remove_revision", RUBY_FUNC_CAST(&version_spec_remove_revision), 0);
rb_define_method(c_version_spec, "revision_only", RUBY_FUNC_CAST(&version_spec_revision_only), 0);
+ rb_define_method(c_version_spec, "bump", RUBY_FUNC_CAST(&version_spec_bump), 0);
+ rb_define_method(c_version_spec, "is_scm?", RUBY_FUNC_CAST(&version_spec_is_scm), 0);
}
}
diff --git a/ruby/version_spec_TEST.rb b/ruby/version_spec_TEST.rb
index 0878e95..bc5ae9c 100644
--- a/ruby/version_spec_TEST.rb
+++ b/ruby/version_spec_TEST.rb
@@ -63,6 +63,19 @@ module Paludis
def test_version_only
assert_equal 'r9', VersionSpec.new('0.1-r9').revision_only
end
+
+ def test_is_scm?
+ assert_equal true, VersionSpec.new('scm').is_scm?
+ assert_equal false, VersionSpec.new('0.1').is_scm?
+ end
+
+ def test_bump
+ assert_equal VersionSpec.new('2'), VersionSpec.new('1').bump
+ assert_equal VersionSpec.new('2'), VersionSpec.new('1.2').bump
+ assert_equal VersionSpec.new('1.3'), VersionSpec.new('1.2.3').bump
+ assert_equal VersionSpec.new('1.3'), VersionSpec.new('1.2.3-r4').bump
+ assert_equal VersionSpec.new('scm'), VersionSpec.new('scm').bump
+ end
end
end