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

Class Attribute Details

.default_timeoutInteger

Return the default timeout

Returns:

  • (Integer)


65
66
67
# File 'lib/sshake/execution_options.rb', line 65

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)


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

def file_to_stream
  @file_to_stream
end

#raise_on_errorBoolean

Should errors be raised?

Returns:

  • (Boolean)


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

def raise_on_error
  @raise_on_error
end

#stderrProc

A proc to call whenever data is received on stderr

Returns:

  • (Proc)


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

def stderr
  @stderr
end

#stdinString

The data to pass to stdin when executing this command

Returns:

  • (String)


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

def stdin
  @stdin
end

#stdoutProc

A proc to call whenever data is received on stdout

Returns:

  • (Proc)


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

def stdout
  @stdout
end

#sudo_passwordString

The password to be provided to the interactive sudo prompt

Returns:

  • (String)


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

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)


20
21
22
# File 'lib/sshake/execution_options.rb', line 20

def sudo_user
  @sudo_user
end

#timeoutInteger

The timeout

Returns:

  • (Integer)


11
12
13
# File 'lib/sshake/execution_options.rb', line 11

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:



99
100
101
102
103
104
# File 'lib/sshake/execution_options.rb', line 99

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:



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/sshake/execution_options.rb', line 74

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)


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

def raise_on_error?
  !!@raise_on_error
end