class CIHelper::Commands::BaseCommand

Attributes

options[RW]

Public Class Methods

call!(**options) click to toggle source
# File lib/ci_helper/commands.rb, line 9
def call!(**options)
  new(**options).call
end
new(**options) click to toggle source
# File lib/ci_helper/commands.rb, line 20
def initialize(**options)
  self.options = options
end
process_stdout() click to toggle source

:nocov:

# File lib/ci_helper/commands.rb, line 14
def process_stdout
  @process_stdout ||= $stdout
end

Public Instance Methods

execute(*commands) click to toggle source
# File lib/ci_helper/commands.rb, line 29
def execute(*commands)
  command = commands.join(" && ")

  process_stdout.puts(Tools::Colorize.command(command))

  Open3.popen2e(command) do |_stdin, stdout, thread|
    stdout.each_char { |char| process_stdout.print(char) }
    exit_code = thread.value.exitstatus

    fail!("Bad exit code #{exit_code} for command #{command.inspect}") unless exit_code.zero?
    0
  end
end
execute_with_env(*commands) click to toggle source
# File lib/ci_helper/commands.rb, line 24
def execute_with_env(*commands)
  commands = ["export RAILS_ENV=#{env}", *commands] if env
  execute(*commands)
end

Private Instance Methods

boolean_option(key) click to toggle source
# File lib/ci_helper/commands.rb, line 57
def boolean_option(key)
  options[key] == "true"
end
create_and_migrate_database!() click to toggle source
# File lib/ci_helper/commands.rb, line 49
def create_and_migrate_database!
  execute_with_env("bundle exec rake db:drop db:create db:migrate")
end
env() click to toggle source
# File lib/ci_helper/commands.rb, line 47
def env; end
fail!(message) click to toggle source
# File lib/ci_helper/commands.rb, line 53
def fail!(message)
  raise Error, message
end
path() click to toggle source
# File lib/ci_helper/commands.rb, line 69
def path
  @path ||= Pathname.pwd
end
plural_option(key) click to toggle source
# File lib/ci_helper/commands.rb, line 61
def plural_option(key)
  return [] unless options.key?(key)
  value = options[key]
  return value if value.is_a?(Array)

  options[key].split(",")
end
process_stdout() click to toggle source
# File lib/ci_helper/commands.rb, line 73
def process_stdout
  self.class.process_stdout
end