Class: Net::SSH::Multi::Subsession

Inherits:
Object
  • Object
show all
Includes:
SessionActions
Defined in:
lib/net/ssh/multi/subsession.rb

Overview

A trivial class for representing a subset of servers. It is used internally for restricting operations to a subset of all defined servers.

subsession = session.with(:app)
subsession.exec("hostname")

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SessionActions

#busy?, #connect!, #exec, #open_channel, #send_global_request, #sessions

Constructor Details

#initialize(master, server_list) ⇒ Subsession

Create a new subsession of the given master session, that operates on the given server_list.



22
23
24
25
# File 'lib/net/ssh/multi/subsession.rb', line 22

def initialize(master, server_list)
  @master  = master
  @servers = server_list.uniq
end

Instance Attribute Details

#masterObject (readonly)

The master session that spawned this subsession.



15
16
17
# File 'lib/net/ssh/multi/subsession.rb', line 15

def master
  @master
end

#serversObject (readonly)

The list of servers that this subsession can operate on.



18
19
20
# File 'lib/net/ssh/multi/subsession.rb', line 18

def servers
  @servers
end

Instance Method Details

#firstObject

Returns a new subsession that consists of only the first server in the server list of the current subsession. This is just convenience for #slice(0):

s1 = subsession.first


43
44
45
# File 'lib/net/ssh/multi/subsession.rb', line 43

def first
  slice(0)
end

#slice(*args) ⇒ Object

Works as Array#slice, but returns a new subsession consisting of the given slice of servers in this subsession. The new subsession will have the same #master session as this subsession does.

s1 = subsession.slice(0)
s2 = subsession.slice(3, -1)
s3 = subsession.slice(1..4)


34
35
36
# File 'lib/net/ssh/multi/subsession.rb', line 34

def slice(*args)
  Subsession.new(master, Array(servers.slice(*args)))
end