Class: EmberCli::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/ember_cli/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(out:, err:, env: {}, options: {}) ⇒ Runner

Returns a new instance of Runner.



7
8
9
10
11
12
13
# File 'lib/ember_cli/runner.rb', line 7

def initialize(out:, err:, env: {}, options: {})
  @env = env
  @output_streams = Array(out)
  @error_streams = Array(err)
  @options = options
  @threads = []
end

Instance Method Details

#run(command) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ember_cli/runner.rb', line 15

def run(command)
  Open3.popen3(env, command, options) do |stdin, stdout, stderr, process|
    stdin.close

    threads << redirect_stream_in_thread(stdout, write_to: output_streams)
    threads << redirect_stream_in_thread(stderr, write_to: error_streams)

    threads.each(&:join)
    process.value
  end
end

#run!(command) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/ember_cli/runner.rb', line 27

def run!(command)
  run(command).tap do |status|
    unless status.success?
      fail BuildError, "`#{command}` failed with status #{status.exitstatus}"
    end
  end
end