Class: Foreplay::Engine::Step
- Inherits:
-
Object
- Object
- Foreplay::Engine::Step
show all
- Includes:
- Foreplay
- Defined in:
- lib/foreplay/engine/step.rb
Constant Summary
Constants included
from Foreplay
DEFAULT_PORT, PORT_GAP, VERSION
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Foreplay
#log, #terminate
Constructor Details
#initialize(h, s, i) ⇒ Step
Returns a new instance of Step.
7
8
9
10
11
12
|
# File 'lib/foreplay/engine/step.rb', line 7
def initialize(h, s, i)
@host = h
@step = s
@instructions = i
@redirect = false
end
|
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
5
6
7
|
# File 'lib/foreplay/engine/step.rb', line 5
def host
@host
end
|
#instructions ⇒ Object
Returns the value of attribute instructions.
5
6
7
|
# File 'lib/foreplay/engine/step.rb', line 5
def instructions
@instructions
end
|
#step ⇒ Object
Returns the value of attribute step.
5
6
7
|
# File 'lib/foreplay/engine/step.rb', line 5
def step
@step
end
|
Instance Method Details
#after ⇒ Object
100
101
102
|
# File 'lib/foreplay/engine/step.rb', line 100
def after
@after ||= step['after'] || ''
end
|
#announce ⇒ Object
116
117
118
119
|
# File 'lib/foreplay/engine/step.rb', line 116
def announce
log (step['commentary'] || command).yellow.to_s, host: host, silent: silent?
log command.cyan, host: host, silent: silent? if instructions['verbose'] && step['commentary'] && command
end
|
#before ⇒ Object
92
93
94
|
# File 'lib/foreplay/engine/step.rb', line 92
def before
@before ||= step['before'] || ''
end
|
#build_commands ⇒ Object
29
30
31
32
|
# File 'lib/foreplay/engine/step.rb', line 29
def build_commands
step['silent'] = !instructions.key?('verbose')
instructions[key].is_a?(Hash) ? build_commands_from_hash : build_commands_from_string
end
|
#build_commands_from_hash ⇒ Object
34
35
36
|
# File 'lib/foreplay/engine/step.rb', line 34
def build_commands_from_hash
delimiter == ': ' ? build_commands_from_hash_to_yaml : build_commands_from_hash_to_env
end
|
#build_commands_from_hash_to_env ⇒ Object
52
53
54
55
56
|
# File 'lib/foreplay/engine/step.rb', line 52
def build_commands_from_hash_to_env
instructions[key].each do |k, v|
@commands << "echo \"#{before}#{k}#{delimiter}#{v}#{after}\" #{redirect} #{filename}"
end
end
|
#build_commands_from_hash_to_yaml ⇒ Object
38
39
40
41
42
|
# File 'lib/foreplay/engine/step.rb', line 38
def build_commands_from_hash_to_yaml
instructions_yaml.each_line do |l|
@commands << "echo \"#{l.remove_trailing_newline.escape_double_quotes}\" #{redirect} #{filename}"
end
end
|
#build_commands_from_string ⇒ Object
58
59
60
|
# File 'lib/foreplay/engine/step.rb', line 58
def build_commands_from_string
@commands << "echo \"#{before}#{delimiter}#{instructions[key]}#{after}\" #{redirect} #{filename}"
end
|
#command ⇒ Object
68
69
70
|
# File 'lib/foreplay/engine/step.rb', line 68
def command
@command ||= step['command']
end
|
#commands ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/foreplay/engine/step.rb', line 14
def commands
return @commands if @commands
@commands = []
if step.key?('key')
build_commands if instructions.key?(step['key'])
else
@commands = [command]
end
@commands
end
|
#delimiter ⇒ Object
96
97
98
|
# File 'lib/foreplay/engine/step.rb', line 96
def delimiter
@delimiter ||= step['delimiter'] || ''
end
|
#filename ⇒ Object
72
73
74
|
# File 'lib/foreplay/engine/step.rb', line 72
def filename
@filename ||= "#{path}#{prefix}#{key}#{suffix}"
end
|
104
105
106
|
# File 'lib/foreplay/engine/step.rb', line 104
def
||= step['header']
end
|
108
109
110
|
# File 'lib/foreplay/engine/step.rb', line 108
def
.present?
end
|
#instructions_hash ⇒ Object
44
45
46
|
# File 'lib/foreplay/engine/step.rb', line 44
def instructions_hash
? { => instructions[key] } : instructions[key]
end
|
#instructions_yaml ⇒ Object
48
49
50
|
# File 'lib/foreplay/engine/step.rb', line 48
def instructions_yaml
YAML.dump instructions_hash
end
|
#key ⇒ Object
76
77
78
|
# File 'lib/foreplay/engine/step.rb', line 76
def key
@key ||= step['key']
end
|
#path ⇒ Object
88
89
90
|
# File 'lib/foreplay/engine/step.rb', line 88
def path
@path ||= step['path'] || ''
end
|
#prefix ⇒ Object
80
81
82
|
# File 'lib/foreplay/engine/step.rb', line 80
def prefix
@prefix ||= step['prefix'] || ''
end
|
#redirect ⇒ Object
62
63
64
65
66
|
# File 'lib/foreplay/engine/step.rb', line 62
def redirect
arrow = @redirect ? '>>' : '>'
@redirect = true
arrow
end
|
#silent? ⇒ Boolean
112
113
114
|
# File 'lib/foreplay/engine/step.rb', line 112
def silent?
@silent ||= step['silent']
end
|
#suffix ⇒ Object
84
85
86
|
# File 'lib/foreplay/engine/step.rb', line 84
def suffix
@suffix ||= step['suffix'] || ''
end
|