Class: Sprinkle::Actors::SSHConnectionCache
- Defined in:
- lib/sprinkle/actors/ssh/connection_cache.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ SSHConnectionCache
constructor
A new instance of SSHConnectionCache.
- #reconnect(host) ⇒ Object
- #shutdown! ⇒ Object
- #start(host, user, opts = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ SSHConnectionCache
Returns a new instance of SSHConnectionCache.
4 5 6 7 |
# File 'lib/sprinkle/actors/ssh/connection_cache.rb', line 4 def initialize(={}) @cache = {} @gateway = Net::SSH::Gateway.new([:gateway], [:user]) if [:gateway] end |
Instance Method Details
#reconnect(host) ⇒ Object
16 17 18 19 20 |
# File 'lib/sprinkle/actors/ssh/connection_cache.rb', line 16 def reconnect(host) @cache.delete_if do |k,v| (v.close; true) if k =~ /^#{host}\// end end |
#shutdown! ⇒ Object
21 22 23 |
# File 'lib/sprinkle/actors/ssh/connection_cache.rb', line 21 def shutdown! @gateway.shutdown! if @gateway end |
#start(host, user, opts = {}) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/sprinkle/actors/ssh/connection_cache.rb', line 8 def start(host, user, opts={}) key="#{host}/#{user}#{opts.to_s}" if @gateway @cache[key] ||= @gateway.ssh(host, user, opts) else @cache[key] ||= Net::SSH.start(host, user, opts) end end |