Class: SSHKit::Custom::Runner::Abstract Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/sshkit/custom/runner/abstract.rb

Overview

This class is abstract.

Subclass and override #apply_block_to_bcks to implement

Base class for all runners

Direct Known Subclasses

Group, Parallel, Sequential

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Abstract

Returns a new instance of Abstract.



52
53
54
# File 'lib/sshkit/custom/runner/abstract.rb', line 52

def initialize(options = nil)
  @options = options || {}
end

Instance Attribute Details

#backendsObject



12
13
14
# File 'lib/sshkit/custom/runner/abstract.rb', line 12

def backends
  @backends
end

#optionsObject (readonly)



13
14
15
# File 'lib/sshkit/custom/runner/abstract.rb', line 13

def options
  @options
end

#wait_interval=(value) ⇒ Object



14
15
16
# File 'lib/sshkit/custom/runner/abstract.rb', line 14

def wait_interval=(value)
  @wait_interval = value
end

Class Method Details

.create_runner(opts) ⇒ Object

Factory method to create a new runner.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sshkit/custom/runner/abstract.rb', line 17

def self.create_runner(opts)
  opts_with_defaults = { in: :parallel }.merge(opts)

  case opts_with_defaults[:in]
  when :parallel
    Parallel
  when :sequence
    Sequential
  when :groups
    Group
  else
    fail "Don't know how to handle run style #{opts_with_defaults[:in].inspect}"
  end.new(opts_with_defaults)
end

Instance Method Details

#apply_block_to_bcks(&_block) ⇒ Object

This method is abstract.


79
80
81
# File 'lib/sshkit/custom/runner/abstract.rb', line 79

def apply_block_to_bcks(&_block)
  fail SSHKit::Backend::MethodUnavailableError
end

#send_cmd(cmd, *args, &block) ⇒ Object

Sends the given command to the backend.

Parameters:

  • cmd (Symbol)

    A command that the sshkit backend supports

  • args (Array)

    Arguments for the backend command



70
71
72
73
74
75
76
# File 'lib/sshkit/custom/runner/abstract.rb', line 70

def send_cmd(cmd, *args, &block)
  args = Array(block.call(active_backend.host)) if block
  active_backend.send(cmd, *args)
rescue => e
  e2 = ExecuteError.new e
  raise e2, "Exception while executing on host #{active_backend.host}: #{e.message}"
end