Class: SSHake::RecordedSession

Inherits:
BaseSession show all
Defined in:
lib/sshake/recorded_session.rb

Instance Attribute Summary collapse

Attributes inherited from BaseSession

#id, #klogger, #raise_on_error

Instance Method Summary collapse

Methods inherited from BaseSession

#connect, #connected?, #disconnect, #kill!, #write_data

Constructor Details

#initialize(recorder, session, **options) ⇒ RecordedSession

Returns a new instance of RecordedSession.



13
14
15
16
17
# File 'lib/sshake/recorded_session.rb', line 13

def initialize(recorder, session, **options)
  super
  @recorder = recorder
  @session = session
end

Instance Attribute Details

#recorderObject (readonly)

Returns the value of attribute recorder.



10
11
12
# File 'lib/sshake/recorded_session.rb', line 10

def recorder
  @recorder
end

#sessionObject (readonly)

Returns the value of attribute session.



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

def session
  @session
end

Instance Method Details

#execute(commands, options = nil, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sshake/recorded_session.rb', line 19

def execute(commands, options = nil, &block)
  options = create_options(options, block)
  command_to_execute = prepare_commands(commands, options)

  cached_response = @recorder.play(command_to_execute, options: options, connection: connection_hash)
  return cached_response if cached_response

  response = @session.execute(commands, options)
  record(command_to_execute, options, response)
  response
end