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