Class: Consolle::Server::EmbeddedSupervisor
- Inherits:
-
BaseSupervisor
- Object
- BaseSupervisor
- Consolle::Server::EmbeddedSupervisor
- Defined in:
- lib/consolle/server/embedded_supervisor.rb
Overview
IRB embedding mode supervisor (Ruby 3.3+) Runs IRB directly in-process without PTY Supports two modes:
-
:embed_irb - Pure IRB without Rails
-
:embed_rails - Rails console with IRB
Constant Summary collapse
- MINIMUM_RUBY_VERSION =
Gem::Version.new('3.3.0')
- VALID_MODES =
%i[embed_irb embed_rails].freeze
Instance Attribute Summary
Attributes inherited from BaseSupervisor
#config, #logger, #rails_env, #rails_root
Class Method Summary collapse
Instance Method Summary collapse
- #eval(code, timeout: nil, pre_sigint: nil) ⇒ Object
-
#initialize(rails_root:, rails_env: 'development', logger: nil, embed_mode: :embed_rails) ⇒ EmbeddedSupervisor
constructor
A new instance of EmbeddedSupervisor.
- #mode ⇒ Object
-
#pid ⇒ Integer
Returns the current process PID (embedded mode runs in-process).
-
#prompt_pattern ⇒ Object
Returns the prompt pattern (for compatibility with PTY mode).
- #restart ⇒ Object
- #running? ⇒ Boolean
- #stop ⇒ Object
Constructor Details
#initialize(rails_root:, rails_env: 'development', logger: nil, embed_mode: :embed_rails) ⇒ EmbeddedSupervisor
Returns a new instance of EmbeddedSupervisor.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/consolle/server/embedded_supervisor.rb', line 38 def initialize(rails_root:, rails_env: 'development', logger: nil, embed_mode: :embed_rails) super(rails_root: rails_root, rails_env: rails_env, logger: logger) @embed_mode = () @running = false @workspace = nil @mutex = Mutex.new boot_environment setup_irb @running = true mode_name = @embed_mode == :embed_rails ? 'Rails console' : 'IRB' logger.info "[EmbeddedSupervisor] #{mode_name} embedded mode initialized (Ruby #{RUBY_VERSION})" end |
Class Method Details
.check_support! ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/consolle/server/embedded_supervisor.rb', line 24 def check_support! return if supported? raise Consolle::Errors::UnsupportedRubyVersion.new( "Embedded mode requires Ruby #{MINIMUM_RUBY_VERSION}+, " \ "current version: #{RUBY_VERSION}" ) end |
.supported? ⇒ Boolean
20 21 22 |
# File 'lib/consolle/server/embedded_supervisor.rb', line 20 def supported? Gem::Version.new(RUBY_VERSION) >= MINIMUM_RUBY_VERSION end |
Instance Method Details
#eval(code, timeout: nil, pre_sigint: nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/consolle/server/embedded_supervisor.rb', line 53 def eval(code, timeout: nil, pre_sigint: nil) # pre_sigint is ignored in embedded mode (no PTY) env_timeout = ENV['CONSOLLE_TIMEOUT']&.to_i timeout = if env_timeout && env_timeout.positive? env_timeout else timeout || 60 end @mutex.synchronize do raise 'Console is not running' unless running? start_time = Time.now execute_code(code, timeout, start_time) end end |
#mode ⇒ Object
89 90 91 |
# File 'lib/consolle/server/embedded_supervisor.rb', line 89 def mode @embed_mode end |
#pid ⇒ Integer
Returns the current process PID (embedded mode runs in-process)
95 96 97 |
# File 'lib/consolle/server/embedded_supervisor.rb', line 95 def pid Process.pid end |
#prompt_pattern ⇒ Object
Returns the prompt pattern (for compatibility with PTY mode)
100 101 102 |
# File 'lib/consolle/server/embedded_supervisor.rb', line 100 def prompt_pattern @config&.prompt_pattern || Consolle::Config::DEFAULT_PROMPT_PATTERN end |
#restart ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/consolle/server/embedded_supervisor.rb', line 81 def restart logger.info '[EmbeddedSupervisor] Restarting IRB workspace...' @mutex.synchronize do setup_irb end logger.info '[EmbeddedSupervisor] IRB workspace restarted' end |
#running? ⇒ Boolean
71 72 73 |
# File 'lib/consolle/server/embedded_supervisor.rb', line 71 def running? @running && @workspace end |
#stop ⇒ Object
75 76 77 78 79 |
# File 'lib/consolle/server/embedded_supervisor.rb', line 75 def stop @running = false @workspace = nil logger.info '[EmbeddedSupervisor] Stopped' end |