| Class | Net::SSH::Multi::ServerList | 
| In: | 
                
                lib/net/ssh/multi/server_list.rb
                
         | 
        
| Parent: | Object | 
Encapsulates a list of server objects, both dynamic (Net::SSH::Multi::DynamicServer) and static (Net::SSH::Multi::Server). It attempts to make it transparent whether a dynamic server set has been evaluated or not. Note that a ServerList is NOT an Array, though it is Enumerable.
Create a new ServerList that wraps the given server list. Duplicate entries will be discarded.
    # File lib/net/ssh/multi/server_list.rb, line 15
15:     def initialize(list=[])
16:       @list = list.uniq
17:     end
          Adds the given server to the list, and returns the argument. If an identical server definition already exists in the collection, the argument is not added, and the existing server record is returned instead.
    # File lib/net/ssh/multi/server_list.rb, line 23
23:     def add(server)
24:       index = @list.index(server)
25:       if index
26:         server = @list[index]
27:       else
28:         @list.push(server)
29:       end
30:       server
31:     end
          Iterates over each distinct server record in the collection. This will correctly iterate over server records instantiated by a DynamicServer as well, but only if the dynamic server has been "evaluated" (see Net::SSH::Multi::DynamicServer#evaluate!).
    # File lib/net/ssh/multi/server_list.rb, line 44
44:     def each
45:       @list.each do |server|
46:         case server
47:         when Server then yield server
48:         when DynamicServer then server.each { |item| yield item }
49:         else raise ArgumentError, "server list contains non-server: #{server.class}"
50:         end
51:       end
52:       self
53:     end
          Returns an array of all servers in the list, with dynamic server records expanded. The result is an array of distinct server records (duplicates are removed from the result).
    # File lib/net/ssh/multi/server_list.rb, line 65
65:     def flatten
66:       result = @list.inject([]) do |aggregator, server|
67:         case server
68:         when Server then aggregator.push(server)
69:         when DynamicServer then aggregator.concat(server)
70:         else raise ArgumentError, "server list contains non-server: #{server.class}"
71:         end
72:       end
73: 
74:       result.uniq
75:     end
          Works exactly as Enumerable#select, but returns the result as a new ServerList instance.
    # File lib/net/ssh/multi/server_list.rb, line 57
57:     def select
58:       subset = @list.select { |i| yield i }
59:       ServerList.new(subset)
60:     end