Module: RactorRailsShim::RunMode
- Defined in:
- lib/ractor_rails_shim/foundation/run_mode.rb
Constant Summary collapse
- THREAD_SERVER_RE =
SERVER values that select thread-server (Puma/Falcon/Thin/Webrick) mode instead of the default Ractor mode. Matched case-insensitively. Kept as a Regex to mirror the original
core.rb:189predicate exactly. /puma|falcon|thin|webrick|thread/i.freeze
Class Method Summary collapse
-
.detect_from_env ⇒ Object
Pure query of the ambient ENV.
-
.reset ⇒ Object
Reset to the unconfigured state.
-
.resolve! ⇒ Object
The install-time decision.
-
.thread=(value) ⇒ Object
Explicitly set the mode.
-
.thread? ⇒ Boolean
The resolved mode: true for thread-server mode, false for Ractor mode.
Class Method Details
.detect_from_env ⇒ Object
Pure query of the ambient ENV. Returns true when the server
name matches a known thread server (puma|falcon|thin|webrick|thread*),
case-insensitively; false otherwise (including when SERVER is unset or
empty). Has no side effects and does not mutate RunMode state — call
resolve! to fold the ENV answer into the resolved mode.
52 53 54 55 56 |
# File 'lib/ractor_rails_shim/foundation/run_mode.rb', line 52 def detect_from_env server = ENV["SERVER"] return false unless server !!(server =~ THREAD_SERVER_RE) end |
.reset ⇒ Object
Reset to the unconfigured state. For specs and teardown; not part of the public install contract.
71 72 73 |
# File 'lib/ractor_rails_shim/foundation/run_mode.rb', line 71 def reset remove_instance_variable(:@thread) if defined?(@thread) end |
.resolve! ⇒ Object
The install-time decision. If the mode has already been set explicitly
(via thread=), keep it — explicit wins over ENV. Otherwise, detect
from ENV and freeze that as the resolved mode. Idempotent: a second
call is a no-op because the first call (or an explicit thread=)
defined @thread.
63 64 65 66 67 |
# File 'lib/ractor_rails_shim/foundation/run_mode.rb', line 63 def resolve! return if defined?(@thread) @thread = detect_from_env @thread end |
.thread=(value) ⇒ Object
Explicitly set the mode. Once called, resolve! becomes a no-op:
explicit configuration wins over ambient ENV. This mirrors the old
install body's unless defined?(@thread_mode) guard, lifted into
the object that owns the state.
43 44 45 |
# File 'lib/ractor_rails_shim/foundation/run_mode.rb', line 43 def thread=(value) @thread = !!value end |
.thread? ⇒ Boolean
The resolved mode: true for thread-server mode, false for Ractor mode.
Defaults to false when never configured. After resolve! or an
explicit thread=, this is sticky — ENV no longer affects it.
34 35 36 37 |
# File 'lib/ractor_rails_shim/foundation/run_mode.rb', line 34 def thread? return @thread if defined?(@thread) false end |