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.



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

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.



27
28
29
# File 'lib/objects/interactive/session.rb', line 27

def node
  @node
end

#responsesObject (readonly)

Returns the value of attribute responses.



27
28
29
# File 'lib/objects/interactive/session.rb', line 27

def responses
  @responses
end

Class Method Details

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



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

def run(node, session_type, init_data = {})
  session_end_message = "\ninteractive session ended\n".informational
  begin
    session = ::Bcome::Interactive::Session.new(node, session_type_to_klass[session_type], 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



19
20
21
22
23
24
# File 'lib/objects/interactive/session.rb', line 19

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

Instance Method Details

#startObject



36
37
38
39
# File 'lib/objects/interactive/session.rb', line 36

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

#start_itemObject



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

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