Module: RactorRailsShim::VersionPolicy
- Defined in:
- lib/ractor_rails_shim/foundation/version_policy.rb
Defined Under Namespace
Modules: Strategy 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 viaregister. {}
Class Attribute Summary collapse
-
.policy ⇒ Object
Policy for version mismatches.
Class Method Summary collapse
-
.applicable ⇒ Object
Report which registered patches apply to the runtime Rails version (and which were skipped because they're untested on it).
-
.check_version_support ⇒ Object
Check Ruby and Rails version support.
-
.mismatch(message) ⇒ Object
Apply the configured policy to a mismatch message.
-
.register(name, *tested_segments) ⇒ Object
Record that a patch was developed/tested against the given Rails version segments.
-
.strategy ⇒ Object
Resolve the strategy module for the current policy.
Class Attribute Details
.policy ⇒ Object
Policy for version mismatches. One of :warn (default), :strict, :off.
Set before install:
RactorRailsShim::VersionPolicy.policy = :strict
Defaults to :warn when never explicitly set.
77 78 79 |
# File 'lib/ractor_rails_shim/foundation/version_policy.rb', line 77 def policy @policy || :warn end |
Class Method Details
.applicable ⇒ Object
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: [...] }.
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/ractor_rails_shim/foundation/version_policy.rb', line 107 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 |
.check_version_support ⇒ Object
Check Ruby and Rails version support. Warns/raises/silences according to the configured policy. Moved from the facade (patches/core.rb) per POODR: this is a version-policy responsibility, not a composition-root responsibility.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/ractor_rails_shim/foundation/version_policy.rb', line 125 def check_version_support unless RactorRailsShim::Version.supported_ruby? msg = "ractor-rails-shim: Ruby #{RUBY_VERSION} — shim requires " \ "Ruby >= #{RactorRailsShim::Version::SUPPORTED_RUBY} (frozen-iseq " \ "call-cache fix #22075 and cross-ractor env-string fix both " \ "shipped in 4.0.6). Proceeding anyway." mismatch(msg) end if RactorRailsShim::Version.rails && !RactorRailsShim::Version.supported_rails? rv = defined?(::Rails::VERSION::STRING) ? ::Rails::VERSION::STRING : "unknown" msg = "ractor-rails-shim: Rails #{rv} — shim developed against " \ "Rails #{RactorRailsShim::Version::TESTED_RAILS.join(", ")}. " \ "Class layouts (class_attribute, callbacks, PathRegistry, etc.) " \ "may differ; patches may miss blockers. Proceeding anyway. " \ "Set RactorRailsShim.version_policy = :strict to make this " \ "fatal; :off to silence." mismatch(msg) end end |
.mismatch(message) ⇒ Object
Apply the configured policy to a mismatch message. Delegates to the
strategy module — no case branch.
92 93 94 |
# File 'lib/ractor_rails_shim/foundation/version_policy.rb', line 92 def mismatch() strategy.mismatch() 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.
99 100 101 102 |
# File 'lib/ractor_rails_shim/foundation/version_policy.rb', line 99 def register(name, *tested_segments) existing = PATCH_VERSIONS[name] || [] PATCH_VERSIONS[name] = (existing + tested_segments).uniq end |
.strategy ⇒ Object
Resolve the strategy module for the current policy. The two call
sites (VersionPolicy.mismatch, CallbackCapture.read_ivar_or_warn)
send a message to this instead of branching on case policy.
86 87 88 |
# File 'lib/ractor_rails_shim/foundation/version_policy.rb', line 86 def strategy Strategy::MAP[policy] || Strategy::Warn end |