newrelic-ruby-agent icon indicating copy to clipboard operation
newrelic-ruby-agent copied to clipboard

Introduce version comparison helper method(s)

Open fallwith opened this issue 3 years ago • 5 comments

The agent currently checks on version numbers of things (Ruby versions, RubyGem versions) in one of two ways:

# String comparison... this is an alphabetical order comparison.
# Not ideal for numbers, but it works ok for Ruby given that the
# minor version has always stayed a single digit.
RUBY_VERSION <= '2.5.9'

# RubyGem version comparison... this is best for everything,
# even versions of things that aren't gems
Gem::Version.new('1.2.3') < Gem::Version.new('1.2.4')

We should standardize on using a RubyGem version comparison in all cases. It would be helpful if we introduced one or more Ruby method helpers like so:

version_greater_than?('1.2.3', '1.2.4')
version_greater_than_or_equal_to?(Gem::Version.new('1.1.3.8'), '8.3.1.1')
version_less_than?(MyClass::VERSION, '4.5.6')
version_less_than_or_equal_to?('7.8.9', '9.8.7')

or like so:

version_satisfied?(version_in_question, :>=, minimum_version)

The method(s) should:

  • Accept nil, an empty string, a string, an integer, a float, or a Gem::Version instance as input for each version
  • Convert the inputted versions to instances of Gem::Version
  • Return a boolean based on the comparison of the two versions

fallwith avatar Apr 27 '22 22:04 fallwith

https://issues.newrelic.com/browse/NEWRELIC-3448