class RubyChecker::Versions
Versions
performs checks on the given versions (current and supported).
Public Class Methods
# File lib/ruby_checker/versions.rb, line 26 def initialize(current:, supported:) @current = current @supported = supported @logger = Logger.new end
Public Instance Methods
check! performs tests for the current and the supported versions of ruby. It returns true if nothing bad is happening, false if there was a warning, and it will raise an OutdatedRubyError
if the version mismatch is unbearable.
# File lib/ruby_checker/versions.rb, line 36 def check! if @current > @supported check_newer_versions elsif @current < @supported check_older_versions! else true end end
Protected Instance Methods
check_newer_versions
performs checks by assuming that the supported version is older than the current one.
Returns true if the difference is on the patch level, false otherwise.
# File lib/ruby_checker/versions.rb, line 52 def check_newer_versions return true if same_major_minor? @logger.warn "Using #{@current}, but #{@supported} is the one supported." false end
check_older_versions! performs checks by assuming that the supported version is newer than the current one.
It returns false if the mismatch is only on the patch level, otherwise it will raise an OutdatedRubyError
.
# File lib/ruby_checker/versions.rb, line 64 def check_older_versions! # Raise an error if this is not a patch-level release mistake, but a major # or minor version difference. raise OutdatedRubyError, @supported unless same_major_minor? # Recommend an upgrade of a patch-level version. @logger.warn "Using #{@current}, but #{@supported} is the one supported." false end
same_major_minor returns true of the supported and the current versions match by the major and the minor numbers of the version.
# File lib/ruby_checker/versions.rb, line 76 def same_major_minor? if RUBY_ENGINE == "truffleruby" @current.to_s.split(".")[0..1] == @supported.to_s.split(".")[0..1] else @current.canonical_segments[0..1] == @supported.canonical_segments[0..1] end end