Class: SSHake::ExecutionOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/sshake/execution_options.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|dsl| ... } ⇒ ExecutionOptions

Returns a new instance of ExecutionOptions.

Yields:

  • (dsl)


8
9
10
11
# File 'lib/sshake/execution_options.rb', line 8

def initialize
  dsl = ExecutionOptionsDSL.new(self)
  yield dsl if block_given?
end

Class Attribute Details

.default_timeoutInteger

Return the default timeout

Returns:

  • (Integer)


70
71
72
# File 'lib/sshake/execution_options.rb', line 70

def default_timeout
  @default_timeout || 60
end

Instance Attribute Details

#file_to_streamFile

A file that you wish to stream to the remote channel with the current commend

Returns:

  • (File)


56
57
58
# File 'lib/sshake/execution_options.rb', line 56

def file_to_stream
  @file_to_stream
end

#raise_on_errorBoolean

Should errors be raised?

Returns:

  • (Boolean)


35
36
37
# File 'lib/sshake/execution_options.rb', line 35

def raise_on_error
  @raise_on_error
end

#stderrProc

A proc to call whenever data is received on stderr

Returns:

  • (Proc)


50
51
52
# File 'lib/sshake/execution_options.rb', line 50

def stderr
  @stderr
end

#stdinString

The data to pass to stdin when executing this command

Returns:

  • (String)


40
41
42
# File 'lib/sshake/execution_options.rb', line 40

def stdin
  @stdin
end

#stdoutProc

A proc to call whenever data is received on stdout

Returns:

  • (Proc)


45
46
47
# File 'lib/sshake/execution_options.rb', line 45

def stdout
  @stdout
end

#sudo_passwordString

The password to be provided to the interactive sudo prompt

Returns:

  • (String)


30
31
32
# File 'lib/sshake/execution_options.rb', line 30

def sudo_password
  @sudo_password
end

#sudo_userString

The user to execute sudo commands as. If nil, commands will not be executed with sudo.

Returns:

  • (String)


25
26
27
# File 'lib/sshake/execution_options.rb', line 25

def sudo_user
  @sudo_user
end

#timeoutInteger

The timeout

Returns:

  • (Integer)


16
17
18
# File 'lib/sshake/execution_options.rb', line 16

def timeout
  @timeout || self.class.default_timeout
end

Class Method Details

.from_block {|dsl| ... } ⇒ SSHake::ExecutionOptions

Create a new set of options from a block

Yields:

  • (dsl)

Returns:



104
105
106
107
108
109
# File 'lib/sshake/execution_options.rb', line 104

def from_block
  options = new
  dsl = ExecutionOptionsDSL.new(options)
  yield dsl
  options
end

.from_hash(hash) ⇒ SSHake::ExecutionOptions

Create a new set of options from a given hash

Parameters:

  • hash (Hash)

Returns:



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/sshake/execution_options.rb', line 79

def from_hash(hash)
  options = new
  options.timeout = hash[:timeout]
  case hash[:sudo]
  when String
    options.sudo_user = hash[:sudo]
  when Hash
    options.sudo_user = hash[:sudo][:user] || 'root'
    options.sudo_password = hash[:sudo][:password]
  when true
    options.sudo_user = 'root'
  end
  # rubocop:disable Style/DoubleNegation
  options.raise_on_error = !!hash[:raise_on_error]
  # rubocop:enable Style/DoubleNegation
  options.stdin = hash[:stdin]
  options.stdout = hash[:stdout]
  options.stderr = hash[:stderr]
  options.file_to_stream = hash[:file_to_stream]
  options
end

Instance Method Details

#raise_on_error?Boolean

Should errors be raised

Returns:

  • (Boolean)


61
62
63
# File 'lib/sshake/execution_options.rb', line 61

def raise_on_error?
  !!@raise_on_error
end