Class: Ora::Cli::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/ora/cli/task.rb

Constant Summary collapse

DEFAULT_DEVELOP_BRANCH =
'develop'
CONTINUE_FILE =
'~/.ora_continue'

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#branchObject (readonly)

Returns the value of attribute branch.



9
10
11
# File 'lib/ora/cli/task.rb', line 9

def branch
  @branch
end

#develop_branchObject (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

Returns the value of attribute print.



9
10
11
# File 'lib/ora/cli/task.rb', line 9

def print
  @print
end

#stdinObject (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

#commandsObject

Raises:



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.expand_path(CONTINUE_FILE)) if @bash.success?
end

#runObject



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

Returns:

  • (Boolean)


57
58
59
# File 'lib/ora/cli/task.rb', line 57

def success?
  @bash.success?
end

#variablesObject



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