Class: Bundlebun::Runner
- Inherits:
-
Object
- Object
- Bundlebun::Runner
- Defined in:
- lib/bundlebun/runner.rb,
sig/bundlebun/runner.rbs
Overview
Runner is the class that bundlebun uses to run the bundled Bun executable.
bundlebun provides two ways to run Bun:
-
Runner.call (also available as Runner.exec): Replaces the current Ruby process with Bun. This is the default.
-
Runner.system: Runs Bun as a subprocess and returns control to Ruby. Use this when you need to continue executing Ruby code after Bun finishes.
Constant Summary collapse
- BINSTUB_PATH =
'bin/bun'- RELATIVE_DIRECTORY =
'lib/bundlebun/vendor/bun'
Class Method Summary collapse
-
.binary_path ⇒ String
A full path to the bundled Bun binary we run (includes
.exeon Windows). -
.binary_path_exist? ⇒ Boolean
Does the bundled Bun binary exist?.
-
.binstub_exist? ⇒ Boolean
Does the binstub exist?.
-
.binstub_or_binary_path ⇒ String
Returns the preferred way to run Bun when bundlebun is installed.
-
.binstub_path ⇒ String
A relative path to binstub that bundlebun usually generates with installation Rake tasks.
-
.call ⇒ bot
Replaces the current Ruby process with Bun.
-
.exec ⇒ bot
Replaces the current Ruby process with Bun.
-
.full_binstub_path ⇒ String
A full path to binstub that bundlebun usually generates with installation Rake tasks.
-
.full_directory ⇒ String
A full directory path to the bundled Bun executable from the root of the gem.
-
.make_shareable ⇒ void
Memoizes every path as frozen values on the main Ractor.
-
.relative_directory ⇒ String
A relative directory path to the bundled Bun executable from the root of the gem.
-
.system ⇒ Boolean?
Runs Bun as a subprocess and returns control to Ruby.
Instance Method Summary collapse
-
#call ⇒ bot
Replaces the current Ruby process with Bun.
-
#exec ⇒ bot
Replaces the current Ruby process with Bun.
-
#initialize(arguments) ⇒ Runner
constructor
Initialize the Runner with arguments to run the Bun runtime later.
-
#system ⇒ Boolean?
Runs Bun as a subprocess and returns control to Ruby.
Constructor Details
#initialize(arguments) ⇒ Runner
Initialize the Bundlebun::Runner with arguments to run the Bun runtime later.
199 200 201 |
# File 'lib/bundlebun/runner.rb', line 199 def initialize(arguments) @arguments = arguments end |
Class Method Details
.binary_path ⇒ String
A full path to the bundled Bun binary we run
(includes .exe on Windows).
139 140 141 142 143 144 |
# File 'lib/bundlebun/runner.rb', line 139 def binary_path return @binary_path if defined?(@binary_path) executable = "bun#{".exe" if Bundlebun::Platform.windows?}" @binary_path = File.join(full_directory, executable).freeze end |
.binary_path_exist? ⇒ Boolean
Does the bundled Bun binary exist?
149 150 151 |
# File 'lib/bundlebun/runner.rb', line 149 def binary_path_exist? File.exist?(binary_path) end |
.binstub_exist? ⇒ Boolean
Does the binstub exist?
182 183 184 |
# File 'lib/bundlebun/runner.rb', line 182 def binstub_exist? File.exist?(binstub_path) end |
.binstub_or_binary_path ⇒ String
Returns the preferred way to run Bun when bundlebun is installed.
If the binstub is installed (see binstub_path), use the full path to binstub. If not, use the full binary path for the bundled executable (binary_path).
159 160 161 |
# File 'lib/bundlebun/runner.rb', line 159 def binstub_or_binary_path binstub_exist? ? full_binstub_path : binary_path end |
.binstub_path ⇒ String
A relative path to binstub that bundlebun usually generates with installation Rake tasks.
For Windows, the binstub path will return the bun.cmd wrapper.
102 103 104 105 106 |
# File 'lib/bundlebun/runner.rb', line 102 def binstub_path return @binstub_path if defined?(@binstub_path) @binstub_path = (Bundlebun::Platform.windows? ? "#{BINSTUB_PATH}.cmd" : BINSTUB_PATH).freeze end |
.call ⇒ bot
Replaces the current Ruby process with Bun. Alias for .exec. Never returns.
67 68 69 |
# File 'lib/bundlebun/runner.rb', line 67 def call(...) exec(...) end |
.exec ⇒ bot
Replaces the current Ruby process with Bun. Never returns.
48 49 50 |
# File 'lib/bundlebun/runner.rb', line 48 def exec(...) new(...).exec end |
.full_binstub_path ⇒ String
A full path to binstub that bundlebun usually generates with installation Rake tasks.
For Windows, that will use the bun.cmd wrapper.
113 114 115 116 117 |
# File 'lib/bundlebun/runner.rb', line 113 def full_binstub_path return @full_binstub_path if defined?(@full_binstub_path) @full_binstub_path = File.(binstub_path).freeze end |
.full_directory ⇒ String
A full directory path to the bundled Bun executable from the root of the gem.
129 130 131 132 133 |
# File 'lib/bundlebun/runner.rb', line 129 def full_directory return @full_directory if defined?(@full_directory) @full_directory = File.("../../#{relative_directory}", __dir__).freeze end |
.make_shareable ⇒ void
This method returns an undefined value.
Memoizes every path as frozen values on the main Ractor. Runs when the file is loaded.
172 173 174 175 176 177 |
# File 'lib/bundlebun/runner.rb', line 172 def make_shareable Bundlebun::Platform.windows? binary_path full_binstub_path nil end |
.relative_directory ⇒ String
A relative directory path to the bundled Bun executable from the root of the gem.
122 123 124 |
# File 'lib/bundlebun/runner.rb', line 122 def relative_directory RELATIVE_DIRECTORY end |
.system ⇒ Boolean?
Runs Bun as a subprocess and returns control to Ruby.
93 94 95 |
# File 'lib/bundlebun/runner.rb', line 93 def system(...) new(...).system end |
Instance Method Details
#call ⇒ bot
Replaces the current Ruby process with Bun. Alias for #exec. Never returns.
228 229 230 |
# File 'lib/bundlebun/runner.rb', line 228 def call exec end |
#exec ⇒ bot
Replaces the current Ruby process with Bun. Never returns.
217 218 219 220 221 |
# File 'lib/bundlebun/runner.rb', line 217 def exec check_executable! instrument('exec.bundlebun') Kernel.exec(*command) end |
#system ⇒ Boolean?
Runs Bun as a subprocess and returns control to Ruby.
251 252 253 254 255 256 |
# File 'lib/bundlebun/runner.rb', line 251 def system check_executable! instrument('system.bundlebun') do Kernel.system(*command) end end |