Class: CIHelper::Commands::BaseCommand
- Inherits:
-
Object
- Object
- CIHelper::Commands::BaseCommand
- Defined in:
- lib/ci_helper/commands.rb
Direct Known Subclasses
BundlerAudit, CheckCoverage, CheckDBDevelopment, CheckDBRollback, CheckSidekiqSchedulerConfig, CheckSpecSuffixes, RubocopLint, RunSpecs
Class Method Summary collapse
- .call! ⇒ Object
-
.process_stdout ⇒ Object
:nocov:.
Instance Method Summary collapse
- #execute(*commands, capture: false) ⇒ Object
- #execute_with_env(*commands) ⇒ Object
-
#initialize(**options) ⇒ BaseCommand
constructor
A new instance of BaseCommand.
Constructor Details
#initialize(**options) ⇒ BaseCommand
Returns a new instance of BaseCommand.
27 28 29 |
# File 'lib/ci_helper/commands.rb', line 27 def initialize(**) self. = end |
Class Method Details
.call! ⇒ Object
16 17 18 |
# File 'lib/ci_helper/commands.rb', line 16 def call!(**) new(**).call end |
.process_stdout ⇒ Object
:nocov:
21 22 23 |
# File 'lib/ci_helper/commands.rb', line 21 def process_stdout @process_stdout ||= $stdout end |
Instance Method Details
#execute(*commands, capture: false) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ci_helper/commands.rb', line 36 def execute(*commands, capture: false) command = commands.join(" && ") process_stdout.puts(Tools::Colorize.command(command)) captured = +"" if capture Open3.popen2e(command) do |_stdin, stdout, thread| stdout.each_char { |char| capture ? captured << char : process_stdout.print(char) } exit_code = thread.value.exitstatus unless exit_code.zero? fail!("Bad exit code #{exit_code} for command #{command.inspect}", output: captured) end 0 end end |
#execute_with_env(*commands) ⇒ Object
31 32 33 34 |
# File 'lib/ci_helper/commands.rb', line 31 def execute_with_env(*commands) commands = ["export RAILS_ENV=#{env}", *commands] if env execute(*commands) end |