summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2008-04-08 20:59:32 -0600
committerJamis Buck <jamis@37signals.com>2008-04-08 20:59:32 -0600
commitb97e7c775049cd5eac3656af04eab5dc7f42ee92 (patch)
tree8390710ca50d8e2c9542aca12f87ca2846363f3a /lib
parent793696dbcf7ac3c763b113f611a56052493f318b (diff)
downloadnet-ssh-multi-b97e7c775049cd5eac3656af04eab5dc7f42ee92.tar.gz
allow session#use to declare multiple servers in a single call
Diffstat (limited to 'lib')
-rw-r--r--lib/net/ssh/multi/session.rb30
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/net/ssh/multi/session.rb b/lib/net/ssh/multi/session.rb
index c7462d6..0f9df0b 100644
--- a/lib/net/ssh/multi/session.rb
+++ b/lib/net/ssh/multi/session.rb
@@ -181,16 +181,28 @@ module Net; module SSH; module Multi
# session.use 'host'
# session.use 'user@host2', :via => nil
# session.use 'host3', :user => "user3", :via => Net::SSH::Gateway.new('gateway.host', 'user')
- def use(host, options={})
- server = Server.new(self, host, {:via => default_gateway}.merge(options))
- exists = servers.index(server)
- if exists
- server = servers[exists]
- else
- servers << server
- group [] => server
+ #
+ # If only a single host is given, the new server instance is returned. You
+ # can give multiple hosts at a time, though, in which case an array of
+ # server instances will be returned.
+ #
+ # server1, server2 = session.use "host1", "host2"
+ def use(*hosts)
+ options = hosts.last.is_a?(Hash) ? hosts.pop : {}
+
+ results = hosts.map do |host|
+ server = Server.new(self, host, {:via => default_gateway}.merge(options))
+ exists = servers.index(server)
+ if exists
+ server = servers[exists]
+ else
+ servers << server
+ end
+ server
end
- server
+
+ group [] => results
+ results.length > 1 ? results : results.first
end
# Returns the set of servers that match the given criteria. It can be used