Class: Ora::Cli::Task
- Inherits:
-
Object
- Object
- Ora::Cli::Task
- Defined in:
- lib/ora/cli/task.rb
Direct Known Subclasses
DeleteFeatureBranct, NewFeatureBranch, PushFeatureBranch, PushTask, PushToMaster, SwitchBranch
Constant Summary collapse
- DEFAULT_DEVELOP_BRANCH =
'develop'- CONTINUE_FILE =
'~/.ora_continue'
Instance Attribute Summary collapse
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#develop_branch ⇒ Object
readonly
Returns the value of attribute develop_branch.
-
#print ⇒ Object
readonly
Returns the value of attribute print.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
Instance Method Summary collapse
- #commands ⇒ Object
- #continue(info) ⇒ Object
-
#initialize(from, inputs: [], print: Print.new, develop_branch: nil) ⇒ Task
constructor
A new instance of Task.
- #run ⇒ Object
- #set_variables(data) ⇒ Object
- #success? ⇒ Boolean
- #variables ⇒ Object
Constructor Details
#initialize(from, inputs: [], print: Print.new, develop_branch: nil) ⇒ Task
Returns a new instance of Task.
14 15 16 17 18 19 20 21 |
# File 'lib/ora/cli/task.rb', line 14 def initialize(from, inputs: [], print: Print.new, develop_branch: nil) @from = from @bash = Bash.new(self, from: @from, print: print) @branch = current_branch @stdin = Stdin.new(bash: @bash, print: print, inputs: inputs) @print = print @develop_branch = develop_branch || DEFAULT_DEVELOP_BRANCH end |
Instance Attribute Details
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
9 10 11 |
# File 'lib/ora/cli/task.rb', line 9 def branch @branch end |
#develop_branch ⇒ Object (readonly)
Returns the value of attribute develop_branch.
9 10 11 |
# File 'lib/ora/cli/task.rb', line 9 def develop_branch @develop_branch end |
#print ⇒ Object (readonly)
Returns the value of attribute print.
9 10 11 |
# File 'lib/ora/cli/task.rb', line 9 def print @print end |
#stdin ⇒ Object (readonly)
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
53 54 55 |
# File 'lib/ora/cli/task.rb', line 53 def commands raise PreconditionError, "Override this method in subclass." end |
#continue(info) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/ora/cli/task.rb', line 30 def continue(info) @print.green("Continue task - #{info['task']}\n") set_variables(info['variables']) @bash.run info['commands'] save_on_fail File.delete(File.(CONTINUE_FILE)) if @bash.success? end |
#run ⇒ Object
23 24 25 26 27 28 |
# File 'lib/ora/cli/task.rb', line 23 def run @bash.run commands save_on_fail rescue PreconditionError => e @print.red("Precondition not met!\n#{e.message}") end |
#set_variables(data) ⇒ Object
49 50 51 |
# File 'lib/ora/cli/task.rb', line 49 def set_variables data data.each { |k, v| instance_variable_set("@#{k}", v) } end |
#success? ⇒ Boolean
57 58 59 |
# File 'lib/ora/cli/task.rb', line 57 def success? @bash.success? end |
#variables ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ora/cli/task.rb', line 38 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 |