Module: RactorRailsShim::VersionPolicy

Defined in:
lib/ractor_rails_shim/version_policy.rb

Defined Under Namespace

Classes: UnsupportedVersionError

Constant Summary collapse

PATCH_VERSIONS =

Registry mapping each install_* patch name to the Rails version segments it was developed and tested against. Populated by register (called by each install_* method). To add 7.x support, write the version-specific patch variant and tag it via register.

{}

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.policyObject

Policy for version mismatches. One of :warn (default), :strict, :off. Set before install:

RactorRailsShim::VersionPolicy.policy = :strict

Defaults to :warn when never explicitly set.



28
29
30
# File 'lib/ractor_rails_shim/version_policy.rb', line 28

def policy
  @policy || :warn
end

Class Method Details

.applicableObject

Report which registered patches apply to the runtime Rails version (and which were skipped because they're untested on it). Returns a Hash: { applied: [...], skipped: [...] }.



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/ractor_rails_shim/version_policy.rb', line 57

def applicable
  seg = RactorRailsShim::Version.rails_segment
  applied = []
  skipped = []
  PATCH_VERSIONS.each do |name, tested|
    if seg.nil? || tested.include?(seg)
      applied << name
    else
      skipped << { name: name, tested: tested, runtime: seg }
    end
  end
  { applied: applied, skipped: skipped }
end

.mismatch(message) ⇒ Object

Apply the configured policy to a mismatch message.



35
36
37
38
39
40
41
42
43
44
# File 'lib/ractor_rails_shim/version_policy.rb', line 35

def mismatch(message)
  case policy
  when :strict
    raise UnsupportedVersionError, message
  when :off
    # silent
  else
    warn message
  end
end

.register(name, *tested_segments) ⇒ Object

Record that a patch was developed/tested against the given Rails version segments. Idempotent and dedupes segments. Called by each install_* method.



49
50
51
52
# File 'lib/ractor_rails_shim/version_policy.rb', line 49

def register(name, *tested_segments)
  existing = PATCH_VERSIONS[name] || []
  PATCH_VERSIONS[name] = (existing + tested_segments).uniq
end