Class: CreateRailsApp::Runner
- Inherits:
-
Object
- Object
- CreateRailsApp::Runner
- Defined in:
- lib/create_rails_app/runner.rb
Overview
Executes commands via the shell.
Supports --dry-run mode, which prints commands instead of running them. Can run multiple commands in sequence (e.g. gem install + rails new).
Instance Method Summary collapse
-
#initialize(out: $stdout, system_runner: nil) ⇒ Runner
constructor
A new instance of Runner.
-
#run!(command, dry_run: false) ⇒ true
Executes the command or prints it in dry-run mode.
Constructor Details
#initialize(out: $stdout, system_runner: nil) ⇒ Runner
Returns a new instance of Runner.
17 18 19 20 |
# File 'lib/create_rails_app/runner.rb', line 17 def initialize(out: $stdout, system_runner: nil) @out = out @system_runner = system_runner || ->(*command) { ::CLI::Kit::System.system(*command) } end |
Instance Method Details
#run!(command, dry_run: false) ⇒ true
Executes the command or prints it in dry-run mode.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/create_rails_app/runner.rb', line 28 def run!(command, dry_run: false) if dry_run @out.puts(command.shelljoin) return true end status = if defined?(Bundler) Bundler.with_unbundled_env { @system_runner.call(*command) } else @system_runner.call(*command) end return true if status.respond_to?(:success?) && status.success? code = status.respond_to?(:exitstatus) ? status.exitstatus : nil = 'Command failed' += " (exit #{code})" if code += ": #{command.shelljoin}" raise Error, end |