Update version according to OSCI-883
[packages/precise/mcollective.git] / doc / MCollective / DDL.html
1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5 <head>
6         <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
7
8         <title>Module: MCollective::DDL</title>
9
10         <link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />
11
12         <script src="../js/jquery.js" type="text/javascript"
13                 charset="utf-8"></script>
14         <script src="../js/thickbox-compressed.js" type="text/javascript"
15                 charset="utf-8"></script>
16         <script src="../js/quicksearch.js" type="text/javascript"
17                 charset="utf-8"></script>
18         <script src="../js/darkfish.js" type="text/javascript"
19                 charset="utf-8"></script>
20
21 </head>
22 <body class="module">
23
24         <div id="metadata">
25                 <div id="file-metadata">
26                         <div id="file-list-section" class="section">
27                                 <h3 class="section-header">In Files</h3>
28                                 <div class="section-body">
29                                         <ul>
30                                         
31                                                 <li><a href="../lib/mcollective/ddl/discoveryddl_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
32                                                         class="thickbox" title="lib/mcollective/ddl/discoveryddl.rb">lib/mcollective/ddl/discoveryddl.rb</a></li>
33                                         
34                                                 <li><a href="../lib/mcollective/ddl/validatorddl_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
35                                                         class="thickbox" title="lib/mcollective/ddl/validatorddl.rb">lib/mcollective/ddl/validatorddl.rb</a></li>
36                                         
37                                                 <li><a href="../lib/mcollective/ddl/agentddl_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
38                                                         class="thickbox" title="lib/mcollective/ddl/agentddl.rb">lib/mcollective/ddl/agentddl.rb</a></li>
39                                         
40                                                 <li><a href="../lib/mcollective/ddl/base_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
41                                                         class="thickbox" title="lib/mcollective/ddl/base.rb">lib/mcollective/ddl/base.rb</a></li>
42                                         
43                                                 <li><a href="../lib/mcollective/ddl/dataddl_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
44                                                         class="thickbox" title="lib/mcollective/ddl/dataddl.rb">lib/mcollective/ddl/dataddl.rb</a></li>
45                                         
46                                                 <li><a href="../lib/mcollective/ddl_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
47                                                         class="thickbox" title="lib/mcollective/ddl.rb">lib/mcollective/ddl.rb</a></li>
48                                         
49                                         </ul>
50                                 </div>
51                         </div>
52
53                         
54                 </div>
55
56                 <div id="class-metadata">
57
58                         <!-- Parent Class -->
59                         
60
61                         <!-- Namespace Contents -->
62                         
63                         <div id="namespace-list-section" class="section">
64                                 <h3 class="section-header">Namespace</h3>
65                                 <ul class="link-list">
66                                         
67                                         <li><span class="type">CLASS</span> <a href="DDL/AgentDDL.html">MCollective::DDL::AgentDDL</a></li>
68                                         
69                                         <li><span class="type">CLASS</span> <a href="DDL/Base.html">MCollective::DDL::Base</a></li>
70                                         
71                                         <li><span class="type">CLASS</span> <a href="DDL/DataDDL.html">MCollective::DDL::DataDDL</a></li>
72                                         
73                                         <li><span class="type">CLASS</span> <a href="DDL/DiscoveryDDL.html">MCollective::DDL::DiscoveryDDL</a></li>
74                                         
75                                         <li><span class="type">CLASS</span> <a href="DDL/ValidatorDDL.html">MCollective::DDL::ValidatorDDL</a></li>
76                                         
77                                 </ul>
78                         </div>
79                         
80
81                         <!-- Method Quickref -->
82                         
83                         <div id="method-list-section" class="section">
84                                 <h3 class="section-header">Methods</h3>
85                                 <ul class="link-list">
86                                         
87                                         <li><a href="#M000368">::load_and_cache</a></li>
88                                         
89                                         <li><a href="#M000367">::new</a></li>
90                                         
91                                         <li><a href="#M000369">::string_to_boolean</a></li>
92                                         
93                                         <li><a href="#M000370">::string_to_number</a></li>
94                                         
95                                         <li><a href="#M000371">::validation_fail!</a></li>
96                                         
97                                 </ul>
98                         </div>
99                         
100
101                         <!-- Included Modules -->
102                         
103                 </div>
104
105                 <div id="project-metadata">
106                         
107                         
108                         <div id="fileindex-section" class="section project-section">
109                                 <h3 class="section-header">Files</h3>
110                                 <ul>
111                                 
112                                         <li class="file"><a href="../COPYING.html">COPYING</a></li>
113                                 
114                                         <li class="file"><a href="../Gemfile.html">Gemfile</a></li>
115                                 
116                                         <li class="file"><a href="../README.html">README</a></li>
117                                 
118                                         <li class="file"><a href="../Rakefile.html">Rakefile</a></li>
119                                 
120                                         <li class="file"><a href="../etc/client_cfg_dist.html">client.cfg.dist</a></li>
121                                 
122                                         <li class="file"><a href="../etc/data-help_erb.html">data-help.erb</a></li>
123                                 
124                                         <li class="file"><a href="../etc/discovery-help_erb.html">discovery-help.erb</a></li>
125                                 
126                                         <li class="file"><a href="../etc/facts_yaml_dist.html">facts.yaml.dist</a></li>
127                                 
128                                         <li class="file"><a href="../etc/metadata-help_erb.html">metadata-help.erb</a></li>
129                                 
130                                         <li class="file"><a href="../etc/msg-help_erb.html">msg-help.erb</a></li>
131                                 
132                                         <li class="file"><a href="../etc/rpc-help_erb.html">rpc-help.erb</a></li>
133                                 
134                                         <li class="file"><a href="../etc/server_cfg_dist.html">server.cfg.dist</a></li>
135                                 
136                                         <li class="file"><a href="../etc/ssl/PLACEHOLDER.html">PLACEHOLDER</a></li>
137                                 
138                                         <li class="file"><a href="../etc/ssl/clients/PLACEHOLDER.html">PLACEHOLDER</a></li>
139                                 
140                                         <li class="file"><a href="../lib/mcollective/generators/templates/action_snippet_erb.html">action_snippet.erb</a></li>
141                                 
142                                         <li class="file"><a href="../lib/mcollective/generators/templates/data_input_snippet_erb.html">data_input_snippet.erb</a></li>
143                                 
144                                         <li class="file"><a href="../lib/mcollective/generators/templates/ddl_erb.html">ddl.erb</a></li>
145                                 
146                                         <li class="file"><a href="../lib/mcollective/generators/templates/plugin_erb.html">plugin.erb</a></li>
147                                 
148                                         <li class="file"><a href="../lib/mcollective/locales/en_yml.html">en.yml</a></li>
149                                 
150                                         <li class="file"><a href="../mcollective_init.html">mcollective.init</a></li>
151                                 
152                                 </ul>
153                         </div>
154                         
155
156                         <div id="classindex-section" class="section project-section">
157                                 <h3 class="section-header">Class Index
158                                         <span class="search-toggle"><img src="../images/find.png"
159                                                 height="16" width="16" alt="[+]"
160                                                 title="show/hide quicksearch" /></span></h3>
161                                 <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
162                                 <fieldset>
163                                         <legend>Quicksearch</legend>
164                                         <input type="text" name="quicksearch" value=""
165                                                 class="quicksearch-field" />
166                                 </fieldset>
167                                 </form>
168
169                                 <ul class="link-list">
170                                 
171                                         <li><a href="../MCollective.html">MCollective</a></li>
172                                 
173                                         <li><a href="../MCollective/Agent.html">MCollective::Agent</a></li>
174                                 
175                                         <li><a href="../MCollective/Agents.html">MCollective::Agents</a></li>
176                                 
177                                         <li><a href="../MCollective/Aggregate.html">MCollective::Aggregate</a></li>
178                                 
179                                         <li><a href="../MCollective/Aggregate/Base.html">MCollective::Aggregate::Base</a></li>
180                                 
181                                         <li><a href="../MCollective/Aggregate/Result.html">MCollective::Aggregate::Result</a></li>
182                                 
183                                         <li><a href="../MCollective/Aggregate/Result/Base.html">MCollective::Aggregate::Result::Base</a></li>
184                                 
185                                         <li><a href="../MCollective/Aggregate/Result/CollectionResult.html">MCollective::Aggregate::Result::CollectionResult</a></li>
186                                 
187                                         <li><a href="../MCollective/Aggregate/Result/NumericResult.html">MCollective::Aggregate::Result::NumericResult</a></li>
188                                 
189                                         <li><a href="../MCollective/Application.html">MCollective::Application</a></li>
190                                 
191                                         <li><a href="../MCollective/Applications.html">MCollective::Applications</a></li>
192                                 
193                                         <li><a href="../MCollective/Cache.html">MCollective::Cache</a></li>
194                                 
195                                         <li><a href="../MCollective/Client.html">MCollective::Client</a></li>
196                                 
197                                         <li><a href="../MCollective/CodedError.html">MCollective::CodedError</a></li>
198                                 
199                                         <li><a href="../MCollective/Config.html">MCollective::Config</a></li>
200                                 
201                                         <li><a href="../MCollective/Connector.html">MCollective::Connector</a></li>
202                                 
203                                         <li><a href="../MCollective/Connector/Base.html">MCollective::Connector::Base</a></li>
204                                 
205                                         <li><a href="../MCollective/DDL.html">MCollective::DDL</a></li>
206                                 
207                                         <li><a href="../MCollective/DDL/AgentDDL.html">MCollective::DDL::AgentDDL</a></li>
208                                 
209                                         <li><a href="../MCollective/DDL/Base.html">MCollective::DDL::Base</a></li>
210                                 
211                                         <li><a href="../MCollective/DDL/DataDDL.html">MCollective::DDL::DataDDL</a></li>
212                                 
213                                         <li><a href="../MCollective/DDL/DiscoveryDDL.html">MCollective::DDL::DiscoveryDDL</a></li>
214                                 
215                                         <li><a href="../MCollective/DDL/ValidatorDDL.html">MCollective::DDL::ValidatorDDL</a></li>
216                                 
217                                         <li><a href="../MCollective/DDLValidationError.html">MCollective::DDLValidationError</a></li>
218                                 
219                                         <li><a href="../MCollective/Data.html">MCollective::Data</a></li>
220                                 
221                                         <li><a href="../MCollective/Data/Base.html">MCollective::Data::Base</a></li>
222                                 
223                                         <li><a href="../MCollective/Data/Result.html">MCollective::Data::Result</a></li>
224                                 
225                                         <li><a href="../MCollective/Discovery.html">MCollective::Discovery</a></li>
226                                 
227                                         <li><a href="../MCollective/Facts.html">MCollective::Facts</a></li>
228                                 
229                                         <li><a href="../MCollective/Facts/Base.html">MCollective::Facts::Base</a></li>
230                                 
231                                         <li><a href="../MCollective/Generators.html">MCollective::Generators</a></li>
232                                 
233                                         <li><a href="../MCollective/Generators/AgentGenerator.html">MCollective::Generators::AgentGenerator</a></li>
234                                 
235                                         <li><a href="../MCollective/Generators/Base.html">MCollective::Generators::Base</a></li>
236                                 
237                                         <li><a href="../MCollective/Generators/DataGenerator.html">MCollective::Generators::DataGenerator</a></li>
238                                 
239                                         <li><a href="../MCollective/InvalidRPCData.html">MCollective::InvalidRPCData</a></li>
240                                 
241                                         <li><a href="../MCollective/Log.html">MCollective::Log</a></li>
242                                 
243                                         <li><a href="../MCollective/Logger.html">MCollective::Logger</a></li>
244                                 
245                                         <li><a href="../MCollective/Logger/Base.html">MCollective::Logger::Base</a></li>
246                                 
247                                         <li><a href="../MCollective/Logger/Console_logger.html">MCollective::Logger::Console_logger</a></li>
248                                 
249                                         <li><a href="../MCollective/Logger/File_logger.html">MCollective::Logger::File_logger</a></li>
250                                 
251                                         <li><a href="../MCollective/Logger/Syslog_logger.html">MCollective::Logger::Syslog_logger</a></li>
252                                 
253                                         <li><a href="../MCollective/Matcher.html">MCollective::Matcher</a></li>
254                                 
255                                         <li><a href="../MCollective/Matcher/Parser.html">MCollective::Matcher::Parser</a></li>
256                                 
257                                         <li><a href="../MCollective/Matcher/Scanner.html">MCollective::Matcher::Scanner</a></li>
258                                 
259                                         <li><a href="../MCollective/Message.html">MCollective::Message</a></li>
260                                 
261                                         <li><a href="../MCollective/MissingRPCData.html">MCollective::MissingRPCData</a></li>
262                                 
263                                         <li><a href="../MCollective/MsgDoesNotMatchRequestID.html">MCollective::MsgDoesNotMatchRequestID</a></li>
264                                 
265                                         <li><a href="../MCollective/MsgTTLExpired.html">MCollective::MsgTTLExpired</a></li>
266                                 
267                                         <li><a href="../MCollective/NotTargettedAtUs.html">MCollective::NotTargettedAtUs</a></li>
268                                 
269                                         <li><a href="../MCollective/Optionparser.html">MCollective::Optionparser</a></li>
270                                 
271                                         <li><a href="../MCollective/PluginManager.html">MCollective::PluginManager</a></li>
272                                 
273                                         <li><a href="../MCollective/PluginPackager.html">MCollective::PluginPackager</a></li>
274                                 
275                                         <li><a href="../MCollective/PluginPackager/AgentDefinition.html">MCollective::PluginPackager::AgentDefinition</a></li>
276                                 
277                                         <li><a href="../MCollective/PluginPackager/StandardDefinition.html">MCollective::PluginPackager::StandardDefinition</a></li>
278                                 
279                                         <li><a href="../MCollective/RPC.html">MCollective::RPC</a></li>
280                                 
281                                         <li><a href="../MCollective/RPC/ActionRunner.html">MCollective::RPC::ActionRunner</a></li>
282                                 
283                                         <li><a href="../MCollective/RPC/Agent.html">MCollective::RPC::Agent</a></li>
284                                 
285                                         <li><a href="../MCollective/RPC/Audit.html">MCollective::RPC::Audit</a></li>
286                                 
287                                         <li><a href="../MCollective/RPC/Client.html">MCollective::RPC::Client</a></li>
288                                 
289                                         <li><a href="../MCollective/RPC/Helpers.html">MCollective::RPC::Helpers</a></li>
290                                 
291                                         <li><a href="../MCollective/RPC/Progress.html">MCollective::RPC::Progress</a></li>
292                                 
293                                         <li><a href="../MCollective/RPC/Reply.html">MCollective::RPC::Reply</a></li>
294                                 
295                                         <li><a href="../MCollective/RPC/Request.html">MCollective::RPC::Request</a></li>
296                                 
297                                         <li><a href="../MCollective/RPC/Result.html">MCollective::RPC::Result</a></li>
298                                 
299                                         <li><a href="../MCollective/RPC/Stats.html">MCollective::RPC::Stats</a></li>
300                                 
301                                         <li><a href="../MCollective/RPCAborted.html">MCollective::RPCAborted</a></li>
302                                 
303                                         <li><a href="../MCollective/RPCError.html">MCollective::RPCError</a></li>
304                                 
305                                         <li><a href="../MCollective/Registration.html">MCollective::Registration</a></li>
306                                 
307                                         <li><a href="../MCollective/Registration/Base.html">MCollective::Registration::Base</a></li>
308                                 
309                                         <li><a href="../MCollective/Runner.html">MCollective::Runner</a></li>
310                                 
311                                         <li><a href="../MCollective/RunnerStats.html">MCollective::RunnerStats</a></li>
312                                 
313                                         <li><a href="../MCollective/SSL.html">MCollective::SSL</a></li>
314                                 
315                                         <li><a href="../MCollective/Security.html">MCollective::Security</a></li>
316                                 
317                                         <li><a href="../MCollective/Security/Base.html">MCollective::Security::Base</a></li>
318                                 
319                                         <li><a href="../MCollective/SecurityValidationFailed.html">MCollective::SecurityValidationFailed</a></li>
320                                 
321                                         <li><a href="../MCollective/Shell.html">MCollective::Shell</a></li>
322                                 
323                                         <li><a href="../MCollective/Translatable.html">MCollective::Translatable</a></li>
324                                 
325                                         <li><a href="../MCollective/UnixDaemon.html">MCollective::UnixDaemon</a></li>
326                                 
327                                         <li><a href="../MCollective/UnknownRPCAction.html">MCollective::UnknownRPCAction</a></li>
328                                 
329                                         <li><a href="../MCollective/UnknownRPCError.html">MCollective::UnknownRPCError</a></li>
330                                 
331                                         <li><a href="../MCollective/Util.html">MCollective::Util</a></li>
332                                 
333                                         <li><a href="../MCollective/Validator.html">MCollective::Validator</a></li>
334                                 
335                                         <li><a href="../MCollective/ValidatorError.html">MCollective::ValidatorError</a></li>
336                                 
337                                         <li><a href="../MCollective/WindowsDaemon.html">MCollective::WindowsDaemon</a></li>
338                                 
339                                         <li><a href="../Array.html">Array</a></li>
340                                 
341                                         <li><a href="../Dir.html">Dir</a></li>
342                                 
343                                         <li><a href="../Object.html">Object</a></li>
344                                 
345                                         <li><a href="../String.html">String</a></li>
346                                 
347                                         <li><a href="../Symbol.html">Symbol</a></li>
348                                 
349                                 </ul>
350                                 <div id="no-class-search-results" style="display: none;">No matching classes.</div>
351                         </div>
352
353                         
354                 </div>
355         </div>
356
357         <div id="documentation">
358                 <h1 class="module">MCollective::DDL</h1>
359
360                 <div id="description">
361                         <p>
362 A set of classes that helps create data description language files for
363 plugins. You can define meta data, actions, input and output describing the
364 behavior of your agent or other plugins
365 </p>
366 <p>
367 <a href="DDL.html">DDL</a> files are used for input validation,
368 constructing outputs, producing online help, informing the various display
369 routines and so forth.
370 </p>
371 <p>
372 A sample <a href="DDL.html">DDL</a> for an agent be seen below, you&#8217;d
373 put this in your agent dir as <agent name>.ddl
374 </p>
375 <pre>
376    metadata :name        =&gt; &quot;SimpleRPC Service Agent&quot;,
377             :description =&gt; &quot;Agent to manage services using the Puppet service provider&quot;,
378             :author      =&gt; &quot;R.I.Pienaar&quot;,
379             :license     =&gt; &quot;GPLv2&quot;,
380             :version     =&gt; &quot;1.1&quot;,
381             :url         =&gt; &quot;http://mcollective-plugins.googlecode.com/&quot;,
382             :timeout     =&gt; 60
383
384    action &quot;status&quot;, :description =&gt; &quot;Gets the status of a service&quot; do
385       display :always
386
387       input :service,
388             :prompt      =&gt; &quot;Service Name&quot;,
389             :description =&gt; &quot;The service to get the status for&quot;,
390             :type        =&gt; :string,
391             :validation  =&gt; '^[a-zA-Z\-_\d]+$',
392             :optional    =&gt; true,
393             :maxlength   =&gt; 30
394
395       output :status,
396              :description =&gt; &quot;The status of service&quot;,
397              :display_as  =&gt; &quot;Service Status&quot;
398   end
399 </pre>
400 <p>
401 There are now many types of <a href="DDL.html">DDL</a> and ultimately all
402 pugins should have <a href="DDL.html">DDL</a> files. The code is organized
403 so that any plugin type will magically just work - they will be an instane
404 of <a href="DDL/Base.html">Base</a> which has metadata and a few common
405 cases.
406 </p>
407 <p>
408 For plugin types that require more specific behaviors they can just add a
409 class here that inherits from <a href="DDL/Base.html">Base</a> and add
410 their specific behavior.
411 </p>
412 <p>
413 <a href="DDL/Base.html">Base</a> defines a specific behavior for input,
414 output and metadata which we&#8217;d like to keep standard across plugin
415 types so do not completely override the behavior of input. The methods are
416 written that they will gladly store extra content though so you add, do not
417 remove. See the <a href="DDL/AgentDDL.html">AgentDDL</a> class for an
418 example where agents want a :required argument to be always set.
419 </p>
420
421                 </div>
422
423                 <!-- Constants -->
424                 
425
426                 <!-- Attributes -->
427                 
428
429                 <!-- Methods -->
430                 
431                 <div id="public-class-method-details" class="method-section section">
432                         <h3 class="section-header">Public Class Methods</h3>
433
434                 
435                         <div id="load-and-cache-method" class="method-detail ">
436                                 <a name="M000368"></a>
437
438                                 <div class="method-heading">
439                                 
440                                         <span class="method-name">load_and_cache</span><span
441                                                 class="method-args">(*args)</span>
442                                         <span class="method-click-advice">click to toggle source</span>
443                                 
444                                 </div>
445
446                                 <div class="method-description">
447                                         
448                                         <p class="missing-docs">(Not documented)</p>
449                                         
450
451                                         
452                                         <div class="method-source-code"
453                                                 id="load-and-cache-source">
454 <pre>
455     <span class="ruby-comment cmt"># File lib/mcollective/ddl.rb, line 71</span>
456 71:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">load_and_cache</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
457 72:       <span class="ruby-constant">Cache</span>.<span class="ruby-identifier">setup</span>(<span class="ruby-identifier">:ddl</span>, <span class="ruby-value">300</span>)
458 73: 
459 74:       <span class="ruby-identifier">plugin</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">first</span>
460 75:       <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">type</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">to_s</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">type</span> = <span class="ruby-value str">&quot;agent&quot;</span>
461 76:       <span class="ruby-identifier">path</span> = <span class="ruby-value str">&quot;%s/%s&quot;</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">type</span>, <span class="ruby-identifier">plugin</span>]
462 77: 
463 78:       <span class="ruby-keyword kw">begin</span>
464 79:         <span class="ruby-identifier">ddl</span> = <span class="ruby-constant">Cache</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">:ddl</span>, <span class="ruby-identifier">path</span>)
465 80:       <span class="ruby-keyword kw">rescue</span>
466 81:         <span class="ruby-keyword kw">begin</span>
467 82:           <span class="ruby-identifier">klass</span> = <span class="ruby-constant">DDL</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-value str">&quot;%sDDL&quot;</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">type</span>.<span class="ruby-identifier">capitalize</span>)
468 83:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">NameError</span>
469 84:           <span class="ruby-identifier">klass</span> = <span class="ruby-constant">Base</span>
470 85:         <span class="ruby-keyword kw">end</span>
471 86: 
472 87:         <span class="ruby-identifier">ddl</span> = <span class="ruby-constant">Cache</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">:ddl</span>, <span class="ruby-identifier">path</span>, <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">new</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>))
473 88:       <span class="ruby-keyword kw">end</span>
474 89: 
475 90:       <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">ddl</span>
476 91:     <span class="ruby-keyword kw">end</span></pre>
477                                         </div>
478                                         
479                                 </div>
480
481                                 
482                         </div>
483
484                 
485                         <div id="new-method" class="method-detail ">
486                                 <a name="M000367"></a>
487
488                                 <div class="method-heading">
489                                 
490                                         <span class="method-name">new</span><span
491                                                 class="method-args">(*args, &blk)</span>
492                                         <span class="method-click-advice">click to toggle source</span>
493                                 
494                                 </div>
495
496                                 <div class="method-description">
497                                         
498                                         <p>
499 There used to be only one big nasty <a href="DDL.html">DDL</a> class with a
500 bunch of mashed together behaviors. It&#8217;s been around for ages and we
501 would rather not ask all the users to change their <a
502 href="DDL.html#M000367">DDL.new</a> calls to some other factory method that
503 would have this exact same behavior.
504 </p>
505 <p>
506 So we override the behavior of <a href="DDL.html#M000367">new</a> which is
507 a hugely sucky thing to do but ultimately it&#8217;s what would be least
508 disrupting to code out there today. We did though change <a
509 href="DDL.html">DDL</a> to a module to make it possibly a little less
510 suprising, possibly.
511 </p>
512                                         
513
514                                         
515                                         <div class="method-source-code"
516                                                 id="new-source">
517 <pre>
518     <span class="ruby-comment cmt"># File lib/mcollective/ddl.rb, line 67</span>
519 67:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">new</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">blk</span>)
520 68:       <span class="ruby-identifier">load_and_cache</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
521 69:     <span class="ruby-keyword kw">end</span></pre>
522                                         </div>
523                                         
524                                 </div>
525
526                                 
527                         </div>
528
529                 
530                         <div id="string-to-boolean-method" class="method-detail ">
531                                 <a name="M000369"></a>
532
533                                 <div class="method-heading">
534                                 
535                                         <span class="method-name">string_to_boolean</span><span
536                                                 class="method-args">(val)</span>
537                                         <span class="method-click-advice">click to toggle source</span>
538                                 
539                                 </div>
540
541                                 <div class="method-description">
542                                         
543                                         <p>
544 As we&#8217;re taking arguments on the command line we need a way to input
545 booleans, true on the cli is a string so this method will take the ddl,
546 find all arguments that are supposed to be boolean and if they are the
547 strings &#8220;true&#8221;/&#8220;yes&#8221; or
548 &#8220;false&#8221;/&#8220;no&#8221; turn them into the matching boolean
549 </p>
550                                         
551
552                                         
553                                         <div class="method-source-code"
554                                                 id="string-to-boolean-source">
555 <pre>
556      <span class="ruby-comment cmt"># File lib/mcollective/ddl.rb, line 98</span>
557  98:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">string_to_boolean</span>(<span class="ruby-identifier">val</span>)
558  99:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">if</span> [<span class="ruby-value str">&quot;true&quot;</span>, <span class="ruby-value str">&quot;t&quot;</span>, <span class="ruby-value str">&quot;yes&quot;</span>, <span class="ruby-value str">&quot;y&quot;</span>, <span class="ruby-value str">&quot;1&quot;</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">val</span>.<span class="ruby-identifier">downcase</span>)
559 100:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> [<span class="ruby-value str">&quot;false&quot;</span>, <span class="ruby-value str">&quot;f&quot;</span>, <span class="ruby-value str">&quot;no&quot;</span>, <span class="ruby-value str">&quot;n&quot;</span>, <span class="ruby-value str">&quot;0&quot;</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">val</span>.<span class="ruby-identifier">downcase</span>)
560 101: 
561 102:       <span class="ruby-identifier">raise_code</span>(<span class="ruby-identifier">:PLMC17</span>, <span class="ruby-value str">&quot;%{value} does not look like a boolean argument&quot;</span>, <span class="ruby-identifier">:debug</span>, <span class="ruby-identifier">:value</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">val</span>)
562 103:     <span class="ruby-keyword kw">end</span></pre>
563                                         </div>
564                                         
565                                 </div>
566
567                                 
568                         </div>
569
570                 
571                         <div id="string-to-number-method" class="method-detail ">
572                                 <a name="M000370"></a>
573
574                                 <div class="method-heading">
575                                 
576                                         <span class="method-name">string_to_number</span><span
577                                                 class="method-args">(val)</span>
578                                         <span class="method-click-advice">click to toggle source</span>
579                                 
580                                 </div>
581
582                                 <div class="method-description">
583                                         
584                                         <p>
585 a generic string to number function, if a number looks like a float it
586 turns it into a float else an int. This is naive but should be sufficient
587 for numbers typed on the cli in most cases
588 </p>
589                                         
590
591                                         
592                                         <div class="method-source-code"
593                                                 id="string-to-number-source">
594 <pre>
595      <span class="ruby-comment cmt"># File lib/mcollective/ddl.rb, line 108</span>
596 108:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">string_to_number</span>(<span class="ruby-identifier">val</span>)
597 109:       <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">val</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^\d+\.\d+$/</span>
598 110:       <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">val</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^\d+$/</span>
599 111: 
600 112:       <span class="ruby-identifier">raise_code</span>(<span class="ruby-identifier">:PLMC16</span>, <span class="ruby-value str">&quot;%{value} does not look like a numeric value&quot;</span>, <span class="ruby-identifier">:debug</span>, <span class="ruby-identifier">:value</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">val</span>)
601 113:     <span class="ruby-keyword kw">end</span></pre>
602                                         </div>
603                                         
604                                 </div>
605
606                                 
607                         </div>
608
609                 
610                         <div id="validation-fail--method" class="method-detail ">
611                                 <a name="M000371"></a>
612
613                                 <div class="method-heading">
614                                 
615                                         <span class="method-name">validation_fail!</span><span
616                                                 class="method-args">(code, default, level, args={})</span>
617                                         <span class="method-click-advice">click to toggle source</span>
618                                 
619                                 </div>
620
621                                 <div class="method-description">
622                                         
623                                         <p>
624 Various <a href="DDL.html">DDL</a> implementations will validate and raise
625 on error, this is a utility method to correctly setup a <a
626 href="DDLValidationError.html">DDLValidationError</a> exceptions and raise
627 them
628 </p>
629                                         
630
631                                         
632                                         <div class="method-source-code"
633                                                 id="validation-fail--source">
634 <pre>
635      <span class="ruby-comment cmt"># File lib/mcollective/ddl.rb, line 117</span>
636 117:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">validation_fail!</span>(<span class="ruby-identifier">code</span>, <span class="ruby-identifier">default</span>, <span class="ruby-identifier">level</span>, <span class="ruby-identifier">args</span>={})
637 118:       <span class="ruby-identifier">exception</span> = <span class="ruby-constant">DDLValidationError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">code</span>, <span class="ruby-identifier">default</span>, <span class="ruby-identifier">level</span>, <span class="ruby-identifier">args</span>)
638 119:       <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">set_backtrace</span> <span class="ruby-identifier">caller</span>
639 120: 
640 121:       <span class="ruby-identifier">raise</span> <span class="ruby-identifier">exception</span>
641 122:     <span class="ruby-keyword kw">end</span></pre>
642                                         </div>
643                                         
644                                 </div>
645
646                                 
647                         </div>
648
649                 
650                 </div>
651         
652
653         </div>
654
655
656         <div id="rdoc-debugging-section-dump" class="debugging-section">
657         
658                 <p>Disabled; run with --debug to generate this.</p>
659         
660         </div>
661
662         <div id="validator-badges">
663                 <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
664                 <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
665                         Rdoc Generator</a> 1.1.6</small>.</p>
666         </div>
667
668 </body>
669 </html>
670