Sha256: bdf5049ebc11dcf7c8efd21e62dfacb3be05ecd2708cd8a3138f101c5f688a8a
Contents?: true
Size: 1.4 KB
Versions: 1
Compression:
Stored size: 1.4 KB
Contents
# frozen_string_literal: true module CIHelper module Commands class Error < StandardError; end class BaseCommand class << self def call!(**options) new(**options).call end # :nocov: def process_stdout @process_stdout ||= STDOUT end # :nocov: end def initialize(**options) self.options = options end def execute_with_env(*commands) commands = ["export RAILS_ENV=#{env}", *commands] if env execute(*commands) end def execute(*commands) command = commands.join(" && ") process_stdout.puts(ColorizedString["> "].green.bold + ColorizedString[command].blue.bold) 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 private attr_accessor :options def env; end def create_and_migrate_database! execute_with_env("bundle exec rake db:drop db:create db:migrate") end def fail!(message) raise Error, message end def path @path ||= Pathname.pwd end def process_stdout self.class.process_stdout end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ci-helper-0.1.0 | lib/ci_helper/commands.rb |