Class: Bcome::Interactive::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/objects/interactive/session.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, item_klass, init_data) ⇒ Session

Returns a new instance of Session.



32
33
34
35
36
37
# File 'lib/objects/interactive/session.rb', line 32

def initialize(node, item_klass, init_data)
  @item_klass = item_klass
  @node = node
  @responses = {}
  @init_data = init_data
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



30
31
32
# File 'lib/objects/interactive/session.rb', line 30

def node
  @node
end

#responsesObject (readonly)

Returns the value of attribute responses.



30
31
32
# File 'lib/objects/interactive/session.rb', line 30

def responses
  @responses
end

Class Method Details

.run(node, session_type, init_data = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/objects/interactive/session.rb', line 6

def run(node, session_type, init_data = {})
  session_end_message = "\ninteractive session ended\n".informational
  begin
    session_klass = session_type.is_a?(Symbol) ? session_type_to_klass[session_type] : session_type
    session = ::Bcome::Interactive::Session.new(node, session_klass, init_data)
    session.start
  rescue ::Bcome::Exception::InteractiveSessionHalt => e
    puts session_end_message
  rescue  ::Bcome::Exception::CouldNotInitiateSshConnection => e
    puts 'Caught connection error #2'
    puts e.message.error
  rescue ::IRB::Abort
    puts session_end_message
  end
end

.session_type_to_klassObject



22
23
24
25
26
27
# File 'lib/objects/interactive/session.rb', line 22

def session_type_to_klass
  {
    interactive_ssh: ::Bcome::Interactive::SessionItem::TransparentSsh,
    capture_input: ::Bcome::Interactive::SessionItem::CaptureInput
  }
end

Instance Method Details

#startObject



39
40
41
42
# File 'lib/objects/interactive/session.rb', line 39

def start
  print start_item.start_message if start_item.has_start_message?
  start_item.do
end

#start_itemObject



44
45
46
# File 'lib/objects/interactive/session.rb', line 44

def start_item
  @start_item ||= @item_klass.new(self, @init_data)
end