Class: CreateRubyGem::Runner
- Inherits:
-
Object
- Object
- CreateRubyGem::Runner
- Defined in:
- lib/create_ruby_gem/runner.rb
Overview
Executes the assembled bundle gem command via the shell.
Supports --dry-run mode, which prints the command instead of running it.
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.
16 17 18 19 |
# File 'lib/create_ruby_gem/runner.rb', line 16 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.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/create_ruby_gem/runner.rb', line 27 def run!(command, dry_run: false) if dry_run @out.puts(command.join(' ')) return true end status = @system_runner.call(*command) return true if status.respond_to?(:success?) && status.success? raise Error, "Command failed: #{command.shelljoin}" end |