Class: Ora::Cli::Task
- Inherits:
-
Object
show all
- Defined in:
- lib/ora/cli/task.rb
Constant Summary
collapse
- DEVELOP_BRANCH =
'develop'
- CONTINUE_FILE =
'~/.ora_continue'
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(from, inputs: [], print: Print.new) ⇒ Task
Returns a new instance of Task.
14
15
16
17
18
19
20
|
# File 'lib/ora/cli/task.rb', line 14
def initialize(from, inputs: [], print: Print.new)
@from = from
@bash = Bash.new(self, from: @from, print: print)
@branch = current_branch
@stdin = Stdin.new(bash: @bash, print: print, inputs: inputs)
@print = print
end
|
Instance Attribute Details
#branch ⇒ Object
Returns the value of attribute branch.
9
10
11
|
# File 'lib/ora/cli/task.rb', line 9
def branch
@branch
end
|
#print ⇒ Object
Returns the value of attribute print.
9
10
11
|
# File 'lib/ora/cli/task.rb', line 9
def print
@print
end
|
#stdin ⇒ Object
Returns the value of attribute stdin.
9
10
11
|
# File 'lib/ora/cli/task.rb', line 9
def stdin
@stdin
end
|
Instance Method Details
#commands ⇒ Object
52
53
54
|
# File 'lib/ora/cli/task.rb', line 52
def commands
raise PreconditionError, "Override this method in subclass."
end
|
#continue(info) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/ora/cli/task.rb', line 29
def continue(info)
@print.green("Continue task - #{info['task']}\n")
set_variables(info['variables'])
@bash.run info['commands']
save_on_fail
File.delete(File.expand_path(CONTINUE_FILE)) if @bash.success?
end
|
#run ⇒ Object
22
23
24
25
26
27
|
# File 'lib/ora/cli/task.rb', line 22
def run
@bash.run commands
save_on_fail
rescue PreconditionError => e
@print.red("Precondition not met!\n#{e.message}")
end
|
#set_variables(data) ⇒ Object
48
49
50
|
# File 'lib/ora/cli/task.rb', line 48
def set_variables data
data.each { |k, v| instance_variable_set("@#{k}", v) }
end
|
#success? ⇒ Boolean
56
57
58
|
# File 'lib/ora/cli/task.rb', line 56
def success?
@bash.success?
end
|
#variables ⇒ Object
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/ora/cli/task.rb', line 37
def variables
instance_variables.inject({}) do |hash, attribute|
value = instance_variable_get(attribute)
if value.to_s.start_with? '#<'
hash
else
hash.merge!(attribute.to_s.sub('@', '') => value)
end
end
end
|