Class: Helm::CommandRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/helm/command-runner.rb

Defined Under Namespace

Classes: CommandExecution

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server_query, command_definition) ⇒ CommandRunner

Returns a new instance of CommandRunner.



7
8
9
10
11
# File 'lib/helm/command-runner.rb', line 7

def initialize(server_query, command_definition)
  @server_query, @command_definition = server_query, command_definition
  @completed = []
  @ran_any = false
end

Instance Attribute Details

#command_definitionObject

Returns the value of attribute command_definition.



13
14
15
# File 'lib/helm/command-runner.rb', line 13

def command_definition
  @command_definition
end

#server_queryObject

Returns the value of attribute server_query.



13
14
15
# File 'lib/helm/command-runner.rb', line 13

def server_query
  @server_query
end

#shellObject

Returns the value of attribute shell.



13
14
15
# File 'lib/helm/command-runner.rb', line 13

def shell
  @shell
end

Instance Method Details

#collect(execution) ⇒ Object



51
52
53
54
# File 'lib/helm/command-runner.rb', line 51

def collect(execution)
  @completed << execution
  command_definition.each_result(execution)
end

#configured_queryObject



31
32
33
34
# File 'lib/helm/command-runner.rb', line 31

def configured_query
  command_definition.configure_query(server_query)
  server_query
end

#finish_runObject



45
46
47
48
49
# File 'lib/helm/command-runner.rb', line 45

def finish_run
  warn "No servers found for #{server_query}!" unless @ran_any
  command_definition.all_results(@completed)
  return true
end

#runObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/helm/command-runner.rb', line 19

def run
  start_run
  catch :fail do
    configured_query.each do |server|
      result = run_one(command_definition.command(server))
      execution = CommandExecution.new(server, result)
      collect(execution)
    end
  end
  finish_run
end

#run_one(single) ⇒ Object



36
37
38
39
# File 'lib/helm/command-runner.rb', line 36

def run_one(single)
  @ran_any = true
  shell.execute(single)
end

#start_runObject



41
42
43
# File 'lib/helm/command-runner.rb', line 41

def start_run
  @ran_any = false
end