Module: RactorRailsShim::Version

Defined in:
lib/ractor_rails_shim/version_check.rb

Constant Summary collapse

SUPPORTED_RUBY =

Ruby version the shim was developed against (major.minor). Ractor semantics are still settling; non-4.0 Rubies may behave differently.

"4.0"
TESTED_RAILS =

Rails versions each patch was tested against. Patches are registered with one or more entries from this list; the dispatcher applies a patch only if the runtime Rails version matches one of its tags. To add 7.x support, write the version-specific patch variants and add the tag here.

["8.1"].freeze

Class Method Summary collapse

Class Method Details

.railsObject

Runtime Rails version as a Gem::Version, or nil if Rails isn't loaded yet (the normal config/boot.rb case — install is called before require "rails").



45
46
47
48
49
50
51
52
53
# File 'lib/ractor_rails_shim/version_check.rb', line 45

def rails
  return nil unless defined?(::Rails) && defined?(::Rails::VERSION)
  return nil if ::Rails::VERSION::STRING.nil? || ::Rails::VERSION::STRING.empty?
  begin
    Gem::Version.new(::Rails::VERSION::STRING)
  rescue ArgumentError
    nil
  end
end

.rails_segmentObject

Major.minor segment as a String ("8.1"), or nil if Rails isn't loaded.



56
57
58
59
# File 'lib/ractor_rails_shim/version_check.rb', line 56

def rails_segment
  return nil unless (rv = rails)
  "#{rv.segments[0]}.#{rv.segments[1]}"
end

.rubyObject

Runtime Ruby version as a Gem::Version (e.g. "4.0.5"). Always available — Ruby is obviously loaded.



38
39
40
# File 'lib/ractor_rails_shim/version_check.rb', line 38

def ruby
  Gem::Version.new(RUBY_VERSION)
end

.ruby_segmentObject

Major.minor segment of the running Ruby.



62
63
64
65
# File 'lib/ractor_rails_shim/version_check.rb', line 62

def ruby_segment
  v = ruby
  "#{v.segments[0]}.#{v.segments[1]}"
end

.satisfies?(segment, requirement) ⇒ Boolean

Compare a runtime segment ("8.1") against a Gem::Requirement string (e.g. ">= 7.0", "~> 8.1"). Returns true if the segment satisfies the requirement. Used by the patch registry to decide applicability.

Returns:

  • (Boolean)


82
83
84
85
# File 'lib/ractor_rails_shim/version_check.rb', line 82

def satisfies?(segment, requirement)
  return false if segment.nil?
  Gem::Requirement.new(requirement).satisfied_by?(Gem::Version.new(segment))
end

.supported_rails?Boolean

True if the runtime Rails major.minor is in the tested set (or Rails isn't loaded yet — can't decide, so optimistic).

Returns:

  • (Boolean)


74
75
76
77
# File 'lib/ractor_rails_shim/version_check.rb', line 74

def supported_rails?
  return true unless rails # Rails not loaded: defer decision.
  TESTED_RAILS.include?(rails_segment)
end

.supported_ruby?Boolean

True if the runtime Ruby's major.minor matches the supported segment.

Returns:

  • (Boolean)


68
69
70
# File 'lib/ractor_rails_shim/version_check.rb', line 68

def supported_ruby?
  ruby_segment == SUPPORTED_RUBY
end