Class: Foreplay::Engine::Remote::Step

Inherits:
Object
  • Object
show all
Includes:
Foreplay
Defined in:
lib/foreplay/engine/remote/step.rb

Constant Summary

Constants included from Foreplay

INDENT, VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Foreplay

#terminate

Constructor Details

#initialize(h, sh, st, i) ⇒ Step

Returns a new instance of Step.



5
6
7
8
9
10
# File 'lib/foreplay/engine/remote/step.rb', line 5

def initialize(h, sh, st, i)
  @host = h
  @shell = sh
  @step = st
  @instructions = i
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



3
4
5
# File 'lib/foreplay/engine/remote/step.rb', line 3

def host
  @host
end

#instructionsObject (readonly)

Returns the value of attribute instructions.



3
4
5
# File 'lib/foreplay/engine/remote/step.rb', line 3

def instructions
  @instructions
end

#shellObject (readonly)

Returns the value of attribute shell.



3
4
5
# File 'lib/foreplay/engine/remote/step.rb', line 3

def shell
  @shell
end

#stepObject (readonly)

Returns the value of attribute step.



3
4
5
# File 'lib/foreplay/engine/remote/step.rb', line 3

def step
  @step
end

Instance Method Details

#deployObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/foreplay/engine/remote/step.rb', line 12

def deploy
  puts "#{host}#{INDENT}#{(step['commentary'] || step['command']).yellow}" unless step['silent'] == true

  # Output from this step
  output    = ''
  previous  = '' # We don't need or want the final CRLF
  commands  = Foreplay::Engine::Step.new(step, instructions).build

  commands.each do |command|
    process = shell.execute command

    process.on_output do |_, o|
      previous = o
      output += previous
    end

    shell.wait!

    if step['ignore_error'] == true || process.exit_status == 0
      print output.gsub!(/^/, "#{host}#{INDENT * 2}") unless step['silent'] == true || output.blank?
    else
      terminate(output)
    end
  end

  output
end