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.
178 179 180 |
# File 'lib/bundlebun/runner.rb', line 178 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).
134 135 136 137 138 139 |
# File 'lib/bundlebun/runner.rb', line 134 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?
144 145 146 |
# File 'lib/bundlebun/runner.rb', line 144 def binary_path_exist? File.exist?(binary_path) end |
.binstub_exist? ⇒ Boolean
Does the binstub exist?
161 162 163 |
# File 'lib/bundlebun/runner.rb', line 161 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).
154 155 156 |
# File 'lib/bundlebun/runner.rb', line 154 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.
101 102 103 |
# File 'lib/bundlebun/runner.rb', line 101 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.
66 67 68 |
# File 'lib/bundlebun/runner.rb', line 66 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.
47 48 49 |
# File 'lib/bundlebun/runner.rb', line 47 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.
110 111 112 |
# File 'lib/bundlebun/runner.rb', line 110 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.
124 125 126 127 128 |
# File 'lib/bundlebun/runner.rb', line 124 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.
117 118 119 |
# File 'lib/bundlebun/runner.rb', line 117 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.
92 93 94 |
# File 'lib/bundlebun/runner.rb', line 92 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.
207 208 209 |
# File 'lib/bundlebun/runner.rb', line 207 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.
196 197 198 199 200 |
# File 'lib/bundlebun/runner.rb', line 196 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.
230 231 232 233 234 235 |
# File 'lib/bundlebun/runner.rb', line 230 def system check_executable! instrument('system.bundlebun') do Kernel.system(*command) end end |