summaryrefslogtreecommitdiff
path: root/classes/Net/SSH/Multi/DynamicServer.html
blob: 376e0b3a78c9a77ed4c14da9cac01bed5424d383 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang='en'>
  <head>
    <title>Net::SSH::Multi::DynamicServer</title>
    <meta content='text/html; charset=US-ASCII' http-equiv='Content-Type'>
    <link href='../../../../css/style.css' media='screen' rel='stylesheet' type='text/css'>
    <script type='text/javascript'>
      //<![CDATA[
        function popupCode(url) {
          window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
        }
        
        function toggleCode(id) {
          var code = document.getElementById(id)
        
          code.style.display = code.style.display != 'block' ? 'block' : 'none'
          return true
        }
        
        // Make codeblocks hidden by default
        document.writeln('<' + 'style type="text/css">.method .source pre { display: none }<\/style>')
      //]]>
    </script>
  </head>
  <body class='page'>
    <div class='class' id='wrapper'>
      <div class='header'>
        <h1 class='name'>
          <span class='type'>class</span>
          Net::SSH::Multi::DynamicServer
        </h1>
        <ol class='paths'>
          <li>
            <a target="docwin" href="../../../../files/lib/net/ssh/multi/dynamic_server_rb.html">lib/net/ssh/multi/dynamic_server.rb</a>
          </li>
        </ol>
        <div class='parent'>
          Parent:
          <strong><a target="docwin" href="../Multi.html">Multi</a></strong>
        </div>
      </div>
      <div id='content'>
        <div id='text'>
          <div id='description'>
            
            <p>Represents a lazily evaluated collection of servers. This will usually be
            created via <a
            href="Session.html#method-i-use">Net::SSH::Multi::Session#use</a>(&amp;block),
            and is useful for creating server definitions where the name or address of
            the servers are not known until run-time.</p>
            
            <pre>session.use { lookup_ip_address_of_server }</pre>
            
            <p>This prevents <code>lookup_ip_address_of_server</code> from being invoked
            unless the server is actually needed, at which point it is invoked and the
            result cached.</p>
            
            <p>The callback should return either <code>nil</code> (in which case no new
            servers are instantiated), a String (representing a connection
            specification), an array of Strings, or an array of <a
            href="Server.html">Net::SSH::Multi::Server</a> instances.</p>
          </div>
          <div id='method-list'>
            <h2>Methods</h2>
            <h3>Public Class</h3>
            <ol>
              <li><a target="docwin" href="#method-c-new">new</a></li>
            </ol>
            <h3>Public Instance</h3>
            <ol>
              <li><a target="docwin" href="#method-i-5B-5D">[]</a></li>
              <li><a target="docwin" href="#method-i-5B-5D-3D">[]=</a></li>
              <li><a target="docwin" href="#attribute-i-callback">callback</a></li>
              <li><a target="docwin" href="#method-i-each">each</a></li>
              <li><a target="docwin" href="#method-i-evaluate-21">evaluate!</a></li>
              <li><a target="docwin" href="#attribute-i-master">master</a></li>
              <li><a target="docwin" href="#attribute-i-options">options</a></li>
            </ol>
          </div>
          <div id='context'>
          </div>
          <div id='section'>
            <div id='aliases-list'>
              <h2>Public Instance Aliases</h2>
              <div class='name-list'>
                <table summary='Public Instance Aliases'>
                  <tr class='top-aligned-row context-row'>
                    <td class='context-item-name'>to_ary</td>
                    <td>-&gt;</td>
                    <td class='context-item-value'><a target="docwin" href="#method-i-evaluate-21">evaluate!</a></td>
                  </tr>
                </table>
              </div>
            </div>
            <div id='attribute-list'>
              <h2 class='section-bar'>Attributes</h2>
              <div class='name-list'>
                <table>
                  <tr class='top-aligned-row context-row'>
                    <td class='context-item-name'>
                      <a name='attribute-i-callback'>callback</a>
                    </td>
                    <td class='context-item-value'>[R]</td>
                    <td class='context-item-desc'>
                      
                      <p>The Proc object to call to evaluate the server(s)</p>
                    </td>
                  </tr>
                  <tr class='top-aligned-row context-row'>
                    <td class='context-item-name'>
                      <a name='attribute-i-master'>master</a>
                    </td>
                    <td class='context-item-value'>[R]</td>
                    <td class='context-item-desc'>
                      
                      <p>The <a href="Session.html">Net::SSH::Multi::Session</a> instance that owns
                      this dynamic server record.</p>
                    </td>
                  </tr>
                  <tr class='top-aligned-row context-row'>
                    <td class='context-item-name'>
                      <a name='attribute-i-options'>options</a>
                    </td>
                    <td class='context-item-value'>[R]</td>
                    <td class='context-item-desc'>
                      
                      <p>The hash of options that will be used to initialize the server records.</p>
                    </td>
                  </tr>
                </table>
              </div>
            </div>
            <div id='methods'>
              <h2>Public Class methods</h2>
              <div class='method public-class' id='method-method-c-new'>
                <a name='method-c-new'></a>
                <div class='synopsis'>
                  <span class='name'>new</span>
                  <span class='arguments'>(master, options, callback)</span>
                </div>
                <div class='description'>
                  
                  <p>Create a new <a href="DynamicServer.html">DynamicServer</a> record, owned
                  by the given <a href="Session.html">Net::SSH::Multi::Session</a>
                  <code>master</code>, with the given hash of <code>options</code>, and using
                  the given Proc <code>callback</code> to lazily evaluate the actual server
                  instances.</p>
                </div>
                <div class='source'>
                  <a class='source-toggle' href='#' onclick="toggleCode('method-c-new-source'); return false">
                    [show source]
                  </a>
                  <pre id='method-c-new-source'><span class="ruby-comment"># File lib/net/ssh/multi/dynamic_server.rb, line 32</span>&#x000A;<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">master</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">callback</span>)&#x000A;  <span class="ruby-ivar">@master</span>, <span class="ruby-ivar">@options</span>, <span class="ruby-ivar">@callback</span> = <span class="ruby-identifier">master</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">callback</span>&#x000A;  <span class="ruby-ivar">@servers</span> = <span class="ruby-keyword">nil</span>&#x000A;<span class="ruby-keyword">end</span></pre>
                </div>
              </div>
              <h2>Public Instance methods</h2>
              <div class='method public-instance' id='method-method-i-5B-5D'>
                <a name='method-i-5B-5D'></a>
                <div class='synopsis'>
                  <span class='name'>[]</span>
                  <span class='arguments'>(key)</span>
                </div>
                <div class='description'>
                  
                  <p>Returns the value for the given <code>key</code> in the :properties hash of
                  the <code>options</code>. If no :properties hash exists in
                  <code>options</code>, this returns <code>nil</code>.</p>
                </div>
                <div class='source'>
                  <a class='source-toggle' href='#' onclick="toggleCode('method-i-5B-5D-source'); return false">
                    [show source]
                  </a>
                  <pre id='method-i-5B-5D-source'><span class="ruby-comment"># File lib/net/ssh/multi/dynamic_server.rb, line 39</span>&#x000A;<span class="ruby-keyword">def</span> <span class="ruby-operator">[]</span>(<span class="ruby-identifier">key</span>)&#x000A;  (<span class="ruby-identifier">options</span>[<span class="ruby-value">:properties</span>] <span class="ruby-operator">||=</span> {})[<span class="ruby-identifier">key</span>]&#x000A;<span class="ruby-keyword">end</span></pre>
                </div>
              </div>
              <div class='method public-instance' id='method-method-i-5B-5D-3D'>
                <a name='method-i-5B-5D-3D'></a>
                <div class='synopsis'>
                  <span class='name'>[]=</span>
                  <span class='arguments'>(key, value)</span>
                </div>
                <div class='description'>
                  
                  <p>Sets the given key/value pair in the <code>:properties</code> key in the
                  options hash. If the options hash has no :properties key, it will be
                  created.</p>
                </div>
                <div class='source'>
                  <a class='source-toggle' href='#' onclick="toggleCode('method-i-5B-5D-3D-source'); return false">
                    [show source]
                  </a>
                  <pre id='method-i-5B-5D-3D-source'><span class="ruby-comment"># File lib/net/ssh/multi/dynamic_server.rb, line 45</span>&#x000A;<span class="ruby-keyword">def</span> <span class="ruby-operator">[]=</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>)&#x000A;  (<span class="ruby-identifier">options</span>[<span class="ruby-value">:properties</span>] <span class="ruby-operator">||=</span> {})[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span>&#x000A;<span class="ruby-keyword">end</span></pre>
                </div>
              </div>
              <div class='method public-instance' id='method-method-i-each'>
                <a name='method-i-each'></a>
                <div class='synopsis'>
                  <span class='name'>each</span>
                  <span class='arguments'>()</span>
                </div>
                <div class='description'>
                  
                  <p>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 <em>not</em> automatically invoke <a
                  href="DynamicServer.html#method-i-evaluate-21">evaluate!</a>).</p>
                </div>
                <div class='source'>
                  <a class='source-toggle' href='#' onclick="toggleCode('method-i-each-source'); return false">
                    [show source]
                  </a>
                  <pre id='method-i-each-source'><span class="ruby-comment"># File lib/net/ssh/multi/dynamic_server.rb, line 52</span>&#x000A;<span class="ruby-keyword">def</span> <span class="ruby-identifier">each</span>&#x000A;  (<span class="ruby-ivar">@servers</span> <span class="ruby-operator">||</span> []).<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span> <span class="ruby-keyword">yield</span> <span class="ruby-identifier">server</span> }&#x000A;<span class="ruby-keyword">end</span></pre>
                </div>
              </div>
              <div class='method public-instance' id='method-method-i-evaluate-21'>
                <a name='method-i-evaluate-21'></a>
                <div class='synopsis'>
                  <span class='name'>evaluate!</span>
                  <span class='arguments'>()</span>
                </div>
                <div class='description'>
                  
                  <p>Evaluates the callback and instantiates the servers, memoizing the result.
                  Subsequent calls to <a
                  href="DynamicServer.html#method-i-evaluate-21">evaluate!</a> will simply
                  return the cached list of servers.</p>
                </div>
                <div class='source'>
                  <a class='source-toggle' href='#' onclick="toggleCode('method-i-evaluate-21-source'); return false">
                    [show source]
                  </a>
                  <pre id='method-i-evaluate-21-source'><span class="ruby-comment"># File lib/net/ssh/multi/dynamic_server.rb, line 59</span>&#x000A;<span class="ruby-keyword">def</span> <span class="ruby-identifier">evaluate!</span>&#x000A;  <span class="ruby-ivar">@servers</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">Array</span>(<span class="ruby-identifier">callback</span>[<span class="ruby-identifier">options</span>]).<span class="ruby-identifier">map</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>&#x000A;      <span class="ruby-keyword">case</span> <span class="ruby-identifier">server</span>&#x000A;      <span class="ruby-keyword">when</span> <span class="ruby-constant">String</span> <span class="ruby-keyword">then</span> <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">SSH</span><span class="ruby-operator">::</span><span class="ruby-constant">Multi</span><span class="ruby-operator">::</span><span class="ruby-constant">Server</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">master</span>, <span class="ruby-identifier">server</span>, <span class="ruby-identifier">options</span>)&#x000A;      <span class="ruby-keyword">else</span> <span class="ruby-identifier">server</span>&#x000A;      <span class="ruby-keyword">end</span>&#x000A;    <span class="ruby-keyword">end</span>&#x000A;<span class="ruby-keyword">end</span></pre>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div id='footer-push'></div>
    </div>
    <div id='footer'>
      <a target="docwin" href="http://github.com/mislav/hanna/tree/master"><strong>Hanna</strong> RDoc template</a>
    </div>
  </body>
</html>