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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jackorp
Copy link

@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
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
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.

2 participants