Class: Jisota::ScriptContext

Inherits:
Object
  • Object
show all
Defined in:
lib/jisota/script_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ScriptContext



5
6
7
8
9
10
# File 'lib/jisota/script_context.rb', line 5

def initialize(options = {})
  @ssh_session = options.fetch(:ssh_session) { nil }
  @logger      = options.fetch(:logger) { NilOutput.new }
  @params      = options.fetch(:params) { Hash.new }
  @packages    = options.fetch(:packages) { Collection.new }
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



3
4
5
# File 'lib/jisota/script_context.rb', line 3

def logger
  @logger
end

#packagesObject

Returns the value of attribute packages.



3
4
5
# File 'lib/jisota/script_context.rb', line 3

def packages
  @packages
end

#paramsObject

Returns the value of attribute params.



3
4
5
# File 'lib/jisota/script_context.rb', line 3

def params
  @params
end

#ssh_sessionObject

Returns the value of attribute ssh_session.



3
4
5
# File 'lib/jisota/script_context.rb', line 3

def ssh_session
  @ssh_session
end

Instance Method Details

#command(cmd) ⇒ Object



12
13
14
# File 'lib/jisota/script_context.rb', line 12

def command(cmd)
  ssh_session.command(cmd, logger)
end

#param_scope(scope_params) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/jisota/script_context.rb', line 16

def param_scope(scope_params)
  old_params = params
  self.params = scope_params
  result = yield if block_given?
  self.params = old_params
  result
end