Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby Bindings: Implement Enumerable for iterable collections #1781

Merged
merged 4 commits into from
Jan 14, 2025

Conversation

jackorp
Copy link
Contributor

@jackorp jackorp commented Oct 17, 2024

Implement including Enumerable and the #each method for iterable collections.

This allows for example to iterate over a package query:

require 'libdnf5/base'

base = Base::Base.new
base.setup()

repo_sack = base.get_repo_sack()
repo_sack.create_repos_from_system_configuration()

rq = Repo::RepoQuery.new(base)
rq.filter_id('rawhide')

repo_sack.load_repos(Repo::Repo::Type_AVAILABLE)

query = Rpm::PackageQuery.new(base)
query.filter_provides("rubygem(httparty)", Common::QueryCmp_EQ)

query.each # Returns => #<Enumerator: ...>
query.each do |pkg|
  puts pkg.get_name
end
# Prints => rubygem-httparty
# And Returns => #<Rpm::PackageSet:0x00007f14d9ecd9a8 @__swigtype__="_p_libdnf5__rpm__PackageSet">

Related issue: #1780

@jackorp jackorp marked this pull request as draft October 17, 2024 17:47
@jackorp jackorp marked this pull request as ready for review October 18, 2024 10:43
@jackorp
Copy link
Contributor Author

jackorp commented Oct 18, 2024

I have implemented #each for collections that I could find, I was just looking for the implemented "begin" method, so not sure if I missed any collections that are also iterable.

Other collections like Reldep or AdvisorySet do not have tests in Ruby so I have not extended them. I can take a stab at creating them if the tests are desired.

@jackorp jackorp changed the title Draft: Ruby Bindings: Implement Enumerable for iterable collections Ruby Bindings: Implement Enumerable for iterable collections Oct 18, 2024
@kontura kontura self-assigned this Nov 7, 2024
@Conan-Kudo Conan-Kudo added this pull request to the merge queue Jan 14, 2025
Merged via the queue into rpm-software-management:main with commit 8ede807 Jan 14, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants