Class: Net::SSH::Multi::DynamicServer

### Home Classes Methods

### In Files

- lib/net/ssh/multi/dynamic_server.rb

### Parent

Object

### Methods

- ::new
- #[]
- #[]=
- #each
- #evaluate!
- #to_ary

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Net
- Net::SSH
- Net::SSH::Multi
- Net::SSH::Multi::Channel
- Net::SSH::Multi::ChannelProxy
- Net::SSH::Multi::DynamicServer
- Net::SSH::Multi::PendingConnection
- Net::SSH::Multi::Server
- Net::SSH::Multi::ServerList
- Net::SSH::Multi::Session
- Net::SSH::Multi::SessionActions
- Net::SSH::Multi::Subsession
- Net::SSH::Multi::Version

No matching classes.

# Net::SSH::Multi::DynamicServer

Represents a lazily evaluated collection of servers. This will usually be created via Net::SSH::Multi::Session#use(&block), and is useful for creating server definitions where the name or address of the servers are not known until run-time.

    session.use { lookup_ip_address_of_server }

This prevents `lookup_ip_address_of_server` from being invoked unless the server is actually needed, at which point it is invoked and the result cached.

The callback should return either `nil` (in which case no new servers are instantiated), a String (representing a connection specification), an array of Strings, or an array of Net::SSH::Multi::Server instances.

### Attributes

callback[R]

The Proc object to call to evaluate the server(s)

master[R]

The Net::SSH::Multi::Session instance that owns this dynamic server record.

options[R]

The hash of options that will be used to initialize the server records.

### Public Class Methods

new(master, options, callback) click to toggle source

Create a new DynamicServer record, owned by the given Net::SSH::Multi::Session `master`, with the given hash of `options`, and using the given Proc `callback` to lazily evaluate the actual server instances.

    # File lib/net/ssh/multi/dynamic_server.rb, line 32
    def initialize(master, options, callback)
      @master, @options, @callback = master, options, callback
      @servers = nil
    end

### Public Instance Methods

[](key) click to toggle source

Returns the value for the given `key` in the :properties hash of the `options`. If no :properties hash exists in `options`, this returns `nil`.

    # File lib/net/ssh/multi/dynamic_server.rb, line 39
    def [](key)
      (options[:properties] ||= {})[key]
    end

[]=(key, value) click to toggle source

Sets the given key/value pair in the `:properties` key in the options hash. If the options hash has no :properties key, it will be created.

    # File lib/net/ssh/multi/dynamic_server.rb, line 45
    def []=(key, value)
      (options[:properties] ||= {})[key] = value
    end

each() click to toggle source

Iterates over every instantiated server record in this dynamic server. If the servers have not yet been instantiated, this does nothing (e.g., it does not automatically invoke evaluate!).

    # File lib/net/ssh/multi/dynamic_server.rb, line 52
    def each
      (@servers || []).each { |server| yield server }
    end

evaluate!() click to toggle source

Evaluates the callback and instantiates the servers, memoizing the result. Subsequent calls to evaluate! will simply return the cached list of servers.

    # File lib/net/ssh/multi/dynamic_server.rb, line 59
    def evaluate!
      @servers ||= Array(callback[options]).map do |server|
          case server
          when String then Net::SSH::Multi::Server.new(master, server, options)
          else server
          end
        end
    end

Also aliased as: to_ary
to_ary() click to toggle source
Alias for: evaluate!

[Validate]

Generated with the Darkfish Rdoc Generator 2.