Class: Bundlebun::Runner
- Inherits:
-
Object
- Object
- Bundlebun::Runner
- Defined in:
- lib/bundlebun/runner.rb
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 ⇒ void
Replaces the current Ruby process with Bun.
-
.exec ⇒ void
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.
-
.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 ⇒ void
Replaces the current Ruby process with Bun.
-
#exec ⇒ void
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.
176 177 178 |
# File 'lib/bundlebun/runner.rb', line 176 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).
132 133 134 135 136 137 |
# File 'lib/bundlebun/runner.rb', line 132 def binary_path return @binary_path if defined?(@binary_path) executable = "bun#{".exe" if Bundlebun::Platform.windows?}" @binary_path = File.join(full_directory, executable) end |
.binary_path_exist? ⇒ Boolean
Does the bundled Bun binary exist?
142 143 144 |
# File 'lib/bundlebun/runner.rb', line 142 def binary_path_exist? File.exist?(binary_path) end |
.binstub_exist? ⇒ Boolean
Does the binstub exist?
159 160 161 |
# File 'lib/bundlebun/runner.rb', line 159 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).
152 153 154 |
# File 'lib/bundlebun/runner.rb', line 152 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.
99 100 101 |
# File 'lib/bundlebun/runner.rb', line 99 def binstub_path Bundlebun::Platform.windows? ? "#{BINSTUB_PATH}.cmd" : BINSTUB_PATH end |
.call ⇒ void
This method returns an undefined value.
Replaces the current Ruby process with Bun. Alias for exec. Also available via the ‘.()` shorthand syntax.
64 65 66 |
# File 'lib/bundlebun/runner.rb', line 64 def call(...) exec(...) end |
.exec ⇒ void
This method returns an undefined value.
Replaces the current Ruby process with Bun.
When ActiveSupport::Notifications is available, this method publishes an exec.bundlebun event before replacing the process. The payload contains ‘{ command: arguments }` where arguments is what was passed to the method.
45 46 47 |
# File 'lib/bundlebun/runner.rb', line 45 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.
108 109 110 |
# File 'lib/bundlebun/runner.rb', line 108 def full_binstub_path File.(binstub_path) end |
.full_directory ⇒ String
A full directory path to the bundled Bun executable from the root of the gem.
122 123 124 125 126 |
# File 'lib/bundlebun/runner.rb', line 122 def full_directory return @full_directory if defined?(@full_directory) @full_directory = File.("../../#{relative_directory}", __dir__) end |
.relative_directory ⇒ String
A relative directory path to the bundled Bun executable from the root of the gem.
115 116 117 |
# File 'lib/bundlebun/runner.rb', line 115 def relative_directory RELATIVE_DIRECTORY end |
.system ⇒ Boolean?
Runs Bun as a subprocess and returns control to Ruby.
Unlike call and exec, this method does not replace the current process. Use this when you need to run Bun and then continue executing Ruby code.
When ActiveSupport::Notifications is available, this method publishes a system.bundlebun event with timing information. The payload contains ‘{ command: arguments }` where arguments is what was passed to the method.
90 91 92 |
# File 'lib/bundlebun/runner.rb', line 90 def system(...) new(...).system end |
Instance Method Details
#call ⇒ void
This method returns an undefined value.
Replaces the current Ruby process with Bun. Alias for #exec.
205 206 207 |
# File 'lib/bundlebun/runner.rb', line 205 def call exec end |
#exec ⇒ void
This method returns an undefined value.
Replaces the current Ruby process with Bun. This is the default behavior.
When ActiveSupport::Notifications is available, this method publishes an exec.bundlebun event before replacing the process. The payload contains ‘{ command: arguments }` where arguments is what was passed to the runner.
194 195 196 197 198 |
# File 'lib/bundlebun/runner.rb', line 194 def exec check_executable! instrument('exec.bundlebun') Kernel.exec(command) end |
#system ⇒ Boolean?
Runs Bun as a subprocess and returns control to Ruby.
Unlike #call and #exec, this method does not replace the current process. Use this when you need to run Bun and then continue executing Ruby code.
When ActiveSupport::Notifications is available, this method publishes a system.bundlebun event with timing information. The payload contains ‘{ command: arguments }` where arguments is what was passed to the runner.
228 229 230 231 232 233 |
# File 'lib/bundlebun/runner.rb', line 228 def system check_executable! instrument('system.bundlebun') do Kernel.system(command) end end |