voxpupuli / rspec-puppet-facts

Simplify your unit tests by looping on every supported Operating System and populating facts.
Apache License 2.0
61 stars 53 forks source link

Rewrite facter_version_for_puppet_version for a better style #183

Open ekohl opened 1 month ago

ekohl commented 1 month ago

This rewrites the code to be easier to follow.

First of all, JSON is parsed and all error handling is local. Using a self closing block avoids having to close a file descriptor and exception handling near the actual code helps understanding.

Then it uses filter_map that Ruby 2.7 introduced to avoid calling .map.compact. It also moves the selection of applicable versions into the mapping.

Includes https://github.com/voxpupuli/rspec-puppet-facts/pull/181.