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">
6 <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
8 <title>Module: MCollective::Matcher</title>
10 <link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />
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>
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">
31 <li><a href="../lib/mcollective/matcher/scanner_rb.html?TB_iframe=true&height=550&width=785"
32 class="thickbox" title="lib/mcollective/matcher/scanner.rb">lib/mcollective/matcher/scanner.rb</a></li>
34 <li><a href="../lib/mcollective/matcher/parser_rb.html?TB_iframe=true&height=550&width=785"
35 class="thickbox" title="lib/mcollective/matcher/parser.rb">lib/mcollective/matcher/parser.rb</a></li>
37 <li><a href="../lib/mcollective/matcher_rb.html?TB_iframe=true&height=550&width=785"
38 class="thickbox" title="lib/mcollective/matcher.rb">lib/mcollective/matcher.rb</a></li>
47 <div id="class-metadata">
52 <!-- Namespace Contents -->
54 <div id="namespace-list-section" class="section">
55 <h3 class="section-header">Namespace</h3>
56 <ul class="link-list">
58 <li><span class="type">CLASS</span> <a href="Matcher/Parser.html">MCollective::Matcher::Parser</a></li>
60 <li><span class="type">CLASS</span> <a href="Matcher/Scanner.html">MCollective::Matcher::Scanner</a></li>
66 <!-- Method Quickref -->
68 <div id="method-list-section" class="section">
69 <h3 class="section-header">Methods</h3>
70 <ul class="link-list">
72 <li><a href="#M000065">::create_compound_callstack</a></li>
74 <li><a href="#M000052">::create_function_hash</a></li>
76 <li><a href="#M000059">::eval_compound_fstatement</a></li>
78 <li><a href="#M000054">::eval_compound_statement</a></li>
80 <li><a href="#M000053">::execute_function</a></li>
86 <!-- Included Modules -->
90 <div id="project-metadata">
93 <div id="fileindex-section" class="section project-section">
94 <h3 class="section-header">Files</h3>
97 <li class="file"><a href="../COPYING.html">COPYING</a></li>
99 <li class="file"><a href="../Gemfile.html">Gemfile</a></li>
101 <li class="file"><a href="../README.html">README</a></li>
103 <li class="file"><a href="../Rakefile.html">Rakefile</a></li>
105 <li class="file"><a href="../etc/client_cfg_dist.html">client.cfg.dist</a></li>
107 <li class="file"><a href="../etc/data-help_erb.html">data-help.erb</a></li>
109 <li class="file"><a href="../etc/discovery-help_erb.html">discovery-help.erb</a></li>
111 <li class="file"><a href="../etc/facts_yaml_dist.html">facts.yaml.dist</a></li>
113 <li class="file"><a href="../etc/metadata-help_erb.html">metadata-help.erb</a></li>
115 <li class="file"><a href="../etc/msg-help_erb.html">msg-help.erb</a></li>
117 <li class="file"><a href="../etc/rpc-help_erb.html">rpc-help.erb</a></li>
119 <li class="file"><a href="../etc/server_cfg_dist.html">server.cfg.dist</a></li>
121 <li class="file"><a href="../etc/ssl/PLACEHOLDER.html">PLACEHOLDER</a></li>
123 <li class="file"><a href="../etc/ssl/clients/PLACEHOLDER.html">PLACEHOLDER</a></li>
125 <li class="file"><a href="../lib/mcollective/generators/templates/action_snippet_erb.html">action_snippet.erb</a></li>
127 <li class="file"><a href="../lib/mcollective/generators/templates/data_input_snippet_erb.html">data_input_snippet.erb</a></li>
129 <li class="file"><a href="../lib/mcollective/generators/templates/ddl_erb.html">ddl.erb</a></li>
131 <li class="file"><a href="../lib/mcollective/generators/templates/plugin_erb.html">plugin.erb</a></li>
133 <li class="file"><a href="../lib/mcollective/locales/en_yml.html">en.yml</a></li>
135 <li class="file"><a href="../mcollective_init.html">mcollective.init</a></li>
141 <div id="classindex-section" class="section project-section">
142 <h3 class="section-header">Class Index
143 <span class="search-toggle"><img src="../images/find.png"
144 height="16" width="16" alt="[+]"
145 title="show/hide quicksearch" /></span></h3>
146 <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
148 <legend>Quicksearch</legend>
149 <input type="text" name="quicksearch" value=""
150 class="quicksearch-field" />
154 <ul class="link-list">
156 <li><a href="../MCollective.html">MCollective</a></li>
158 <li><a href="../MCollective/Agent.html">MCollective::Agent</a></li>
160 <li><a href="../MCollective/Agents.html">MCollective::Agents</a></li>
162 <li><a href="../MCollective/Aggregate.html">MCollective::Aggregate</a></li>
164 <li><a href="../MCollective/Aggregate/Base.html">MCollective::Aggregate::Base</a></li>
166 <li><a href="../MCollective/Aggregate/Result.html">MCollective::Aggregate::Result</a></li>
168 <li><a href="../MCollective/Aggregate/Result/Base.html">MCollective::Aggregate::Result::Base</a></li>
170 <li><a href="../MCollective/Aggregate/Result/CollectionResult.html">MCollective::Aggregate::Result::CollectionResult</a></li>
172 <li><a href="../MCollective/Aggregate/Result/NumericResult.html">MCollective::Aggregate::Result::NumericResult</a></li>
174 <li><a href="../MCollective/Application.html">MCollective::Application</a></li>
176 <li><a href="../MCollective/Applications.html">MCollective::Applications</a></li>
178 <li><a href="../MCollective/Cache.html">MCollective::Cache</a></li>
180 <li><a href="../MCollective/Client.html">MCollective::Client</a></li>
182 <li><a href="../MCollective/CodedError.html">MCollective::CodedError</a></li>
184 <li><a href="../MCollective/Config.html">MCollective::Config</a></li>
186 <li><a href="../MCollective/Connector.html">MCollective::Connector</a></li>
188 <li><a href="../MCollective/Connector/Base.html">MCollective::Connector::Base</a></li>
190 <li><a href="../MCollective/DDL.html">MCollective::DDL</a></li>
192 <li><a href="../MCollective/DDL/AgentDDL.html">MCollective::DDL::AgentDDL</a></li>
194 <li><a href="../MCollective/DDL/Base.html">MCollective::DDL::Base</a></li>
196 <li><a href="../MCollective/DDL/DataDDL.html">MCollective::DDL::DataDDL</a></li>
198 <li><a href="../MCollective/DDL/DiscoveryDDL.html">MCollective::DDL::DiscoveryDDL</a></li>
200 <li><a href="../MCollective/DDL/ValidatorDDL.html">MCollective::DDL::ValidatorDDL</a></li>
202 <li><a href="../MCollective/DDLValidationError.html">MCollective::DDLValidationError</a></li>
204 <li><a href="../MCollective/Data.html">MCollective::Data</a></li>
206 <li><a href="../MCollective/Data/Base.html">MCollective::Data::Base</a></li>
208 <li><a href="../MCollective/Data/Result.html">MCollective::Data::Result</a></li>
210 <li><a href="../MCollective/Discovery.html">MCollective::Discovery</a></li>
212 <li><a href="../MCollective/Facts.html">MCollective::Facts</a></li>
214 <li><a href="../MCollective/Facts/Base.html">MCollective::Facts::Base</a></li>
216 <li><a href="../MCollective/Generators.html">MCollective::Generators</a></li>
218 <li><a href="../MCollective/Generators/AgentGenerator.html">MCollective::Generators::AgentGenerator</a></li>
220 <li><a href="../MCollective/Generators/Base.html">MCollective::Generators::Base</a></li>
222 <li><a href="../MCollective/Generators/DataGenerator.html">MCollective::Generators::DataGenerator</a></li>
224 <li><a href="../MCollective/InvalidRPCData.html">MCollective::InvalidRPCData</a></li>
226 <li><a href="../MCollective/Log.html">MCollective::Log</a></li>
228 <li><a href="../MCollective/Logger.html">MCollective::Logger</a></li>
230 <li><a href="../MCollective/Logger/Base.html">MCollective::Logger::Base</a></li>
232 <li><a href="../MCollective/Logger/Console_logger.html">MCollective::Logger::Console_logger</a></li>
234 <li><a href="../MCollective/Logger/File_logger.html">MCollective::Logger::File_logger</a></li>
236 <li><a href="../MCollective/Logger/Syslog_logger.html">MCollective::Logger::Syslog_logger</a></li>
238 <li><a href="../MCollective/Matcher.html">MCollective::Matcher</a></li>
240 <li><a href="../MCollective/Matcher/Parser.html">MCollective::Matcher::Parser</a></li>
242 <li><a href="../MCollective/Matcher/Scanner.html">MCollective::Matcher::Scanner</a></li>
244 <li><a href="../MCollective/Message.html">MCollective::Message</a></li>
246 <li><a href="../MCollective/MissingRPCData.html">MCollective::MissingRPCData</a></li>
248 <li><a href="../MCollective/MsgDoesNotMatchRequestID.html">MCollective::MsgDoesNotMatchRequestID</a></li>
250 <li><a href="../MCollective/MsgTTLExpired.html">MCollective::MsgTTLExpired</a></li>
252 <li><a href="../MCollective/NotTargettedAtUs.html">MCollective::NotTargettedAtUs</a></li>
254 <li><a href="../MCollective/Optionparser.html">MCollective::Optionparser</a></li>
256 <li><a href="../MCollective/PluginManager.html">MCollective::PluginManager</a></li>
258 <li><a href="../MCollective/PluginPackager.html">MCollective::PluginPackager</a></li>
260 <li><a href="../MCollective/PluginPackager/AgentDefinition.html">MCollective::PluginPackager::AgentDefinition</a></li>
262 <li><a href="../MCollective/PluginPackager/StandardDefinition.html">MCollective::PluginPackager::StandardDefinition</a></li>
264 <li><a href="../MCollective/RPC.html">MCollective::RPC</a></li>
266 <li><a href="../MCollective/RPC/ActionRunner.html">MCollective::RPC::ActionRunner</a></li>
268 <li><a href="../MCollective/RPC/Agent.html">MCollective::RPC::Agent</a></li>
270 <li><a href="../MCollective/RPC/Audit.html">MCollective::RPC::Audit</a></li>
272 <li><a href="../MCollective/RPC/Client.html">MCollective::RPC::Client</a></li>
274 <li><a href="../MCollective/RPC/Helpers.html">MCollective::RPC::Helpers</a></li>
276 <li><a href="../MCollective/RPC/Progress.html">MCollective::RPC::Progress</a></li>
278 <li><a href="../MCollective/RPC/Reply.html">MCollective::RPC::Reply</a></li>
280 <li><a href="../MCollective/RPC/Request.html">MCollective::RPC::Request</a></li>
282 <li><a href="../MCollective/RPC/Result.html">MCollective::RPC::Result</a></li>
284 <li><a href="../MCollective/RPC/Stats.html">MCollective::RPC::Stats</a></li>
286 <li><a href="../MCollective/RPCAborted.html">MCollective::RPCAborted</a></li>
288 <li><a href="../MCollective/RPCError.html">MCollective::RPCError</a></li>
290 <li><a href="../MCollective/Registration.html">MCollective::Registration</a></li>
292 <li><a href="../MCollective/Registration/Base.html">MCollective::Registration::Base</a></li>
294 <li><a href="../MCollective/Runner.html">MCollective::Runner</a></li>
296 <li><a href="../MCollective/RunnerStats.html">MCollective::RunnerStats</a></li>
298 <li><a href="../MCollective/SSL.html">MCollective::SSL</a></li>
300 <li><a href="../MCollective/Security.html">MCollective::Security</a></li>
302 <li><a href="../MCollective/Security/Base.html">MCollective::Security::Base</a></li>
304 <li><a href="../MCollective/SecurityValidationFailed.html">MCollective::SecurityValidationFailed</a></li>
306 <li><a href="../MCollective/Shell.html">MCollective::Shell</a></li>
308 <li><a href="../MCollective/Translatable.html">MCollective::Translatable</a></li>
310 <li><a href="../MCollective/UnixDaemon.html">MCollective::UnixDaemon</a></li>
312 <li><a href="../MCollective/UnknownRPCAction.html">MCollective::UnknownRPCAction</a></li>
314 <li><a href="../MCollective/UnknownRPCError.html">MCollective::UnknownRPCError</a></li>
316 <li><a href="../MCollective/Util.html">MCollective::Util</a></li>
318 <li><a href="../MCollective/Validator.html">MCollective::Validator</a></li>
320 <li><a href="../MCollective/ValidatorError.html">MCollective::ValidatorError</a></li>
322 <li><a href="../MCollective/WindowsDaemon.html">MCollective::WindowsDaemon</a></li>
324 <li><a href="../Array.html">Array</a></li>
326 <li><a href="../Dir.html">Dir</a></li>
328 <li><a href="../Object.html">Object</a></li>
330 <li><a href="../String.html">String</a></li>
332 <li><a href="../Symbol.html">Symbol</a></li>
335 <div id="no-class-search-results" style="display: none;">No matching classes.</div>
342 <div id="documentation">
343 <h1 class="module">MCollective::Matcher</h1>
345 <div id="description">
347 A parser and scanner that creates a stack machine for a simple fact and
348 class matching language used on the CLI to facilitate a rich discovery
355 compound = [“(“] expression [“)”]
356 {[“(“] expression [“)”]} expression =
357 [!|not]statement [“and”|“or”] [!|not] statement
358 char = A-Z | a-z | < | > | => | =< | _ | - |* | / { A-Z | a-z | < | > | =>
359 | =< | _ | - | * | / | } int = 0|1|2|3|4|5|6|7|8|9{|0|1|2|3|4|5|6|7|8|9|0}
372 <div id="public-class-method-details" class="method-section section">
373 <h3 class="section-header">Public Class Methods</h3>
376 <div id="create-compound-callstack-method" class="method-detail ">
377 <a name="M000065"></a>
379 <div class="method-heading">
381 <span class="method-name">create_compound_callstack</span><span
382 class="method-args">(call_string)</span>
383 <span class="method-click-advice">click to toggle source</span>
387 <div class="method-description">
390 Creates a callstack to be evaluated from a compound evaluation string
395 <div class="method-source-code"
396 id="create-compound-callstack-source">
398 <span class="ruby-comment cmt"># File lib/mcollective/matcher.rb, line 181</span>
399 181: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">create_compound_callstack</span>(<span class="ruby-identifier">call_string</span>)
400 182: <span class="ruby-identifier">callstack</span> = <span class="ruby-constant">Matcher</span><span class="ruby-operator">::</span><span class="ruby-constant">Parser</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">call_string</span>).<span class="ruby-identifier">execution_stack</span>
401 183: <span class="ruby-identifier">callstack</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">statement</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
402 184: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">==</span> <span class="ruby-value str">"fstatement"</span>
403 185: <span class="ruby-identifier">callstack</span>[<span class="ruby-identifier">i</span>][<span class="ruby-value str">"fstatement"</span>] = <span class="ruby-identifier">create_function_hash</span>(<span class="ruby-identifier">statement</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span>)
404 186: <span class="ruby-keyword kw">end</span>
405 187: <span class="ruby-keyword kw">end</span>
406 188: <span class="ruby-identifier">callstack</span>
407 189: <span class="ruby-keyword kw">end</span></pre>
416 <div id="create-function-hash-method" class="method-detail ">
417 <a name="M000052"></a>
419 <div class="method-heading">
421 <span class="method-name">create_function_hash</span><span
422 class="method-args">(function_call)</span>
423 <span class="method-click-advice">click to toggle source</span>
427 <div class="method-description">
430 Helper creates a hash from a function call string
435 <div class="method-source-code"
436 id="create-function-hash-source">
438 <span class="ruby-comment cmt"># File lib/mcollective/matcher.rb, line 17</span>
439 17: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">create_function_hash</span>(<span class="ruby-identifier">function_call</span>)
440 18: <span class="ruby-identifier">func_hash</span> = {}
441 19: <span class="ruby-identifier">f</span> = <span class="ruby-value str">""</span>
442 20: <span class="ruby-identifier">func_parts</span> = <span class="ruby-identifier">function_call</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">/(!=|>=|<=|<|>|=)/</span>)
443 21: <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">"r_compare"</span>] = <span class="ruby-identifier">func_parts</span>.<span class="ruby-identifier">pop</span>
444 22: <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">"operator"</span>] = <span class="ruby-identifier">func_parts</span>.<span class="ruby-identifier">pop</span>
445 23: <span class="ruby-identifier">func</span> = <span class="ruby-identifier">func_parts</span>.<span class="ruby-identifier">join</span>
447 25: <span class="ruby-comment cmt"># Deal with dots in function parameters and functions without dot values</span>
448 26: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">func</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/^.+\(.*\)$/</span>)
449 27: <span class="ruby-identifier">f</span> = <span class="ruby-identifier">func</span>
450 28: <span class="ruby-keyword kw">else</span>
451 29: <span class="ruby-identifier">func_parts</span> = <span class="ruby-identifier">func</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">"."</span>)
452 30: <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">"value"</span>] = <span class="ruby-identifier">func_parts</span>.<span class="ruby-identifier">pop</span>
453 31: <span class="ruby-identifier">f</span> = <span class="ruby-identifier">func_parts</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">"."</span>)
454 32: <span class="ruby-keyword kw">end</span>
456 34: <span class="ruby-comment cmt"># Deal with regular expression matches</span>
457 35: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">"r_compare"</span>] <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^\/.*\/$/</span>
458 36: <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">"operator"</span>] = <span class="ruby-value str">"=~"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">"operator"</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">"="</span>
459 37: <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">"operator"</span>] = <span class="ruby-value str">"!=~"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">"operator"</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">"!="</span>
460 38: <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">"r_compare"</span>] = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">"r_compare"</span>].<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/^\/|\/$/</span>, <span class="ruby-value str">""</span>))
461 39: <span class="ruby-comment cmt"># Convert = operators to == so they can be propperly evaluated</span>
462 40: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">"operator"</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">"="</span>
463 41: <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">"operator"</span>] = <span class="ruby-value str">"=="</span>
464 42: <span class="ruby-keyword kw">end</span>
466 44: <span class="ruby-comment cmt"># Grab function name and parameters from left compare string</span>
467 45: <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">"name"</span>], <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">"params"</span>] = <span class="ruby-identifier">f</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">"("</span>)
468 46: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">"params"</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">")"</span>
469 47: <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">"params"</span>] = <span class="ruby-keyword kw">nil</span>
470 48: <span class="ruby-keyword kw">else</span>
472 50: <span class="ruby-comment cmt"># Walk the function parameters from the front and from the</span>
473 51: <span class="ruby-comment cmt"># back removing the first and last instances of single of</span>
474 52: <span class="ruby-comment cmt"># double qoutes. We do this to handle the case where params</span>
475 53: <span class="ruby-comment cmt"># contain escaped qoutes.</span>
476 54: <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">"params"</span>] = <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">"params"</span>].<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">")"</span>, <span class="ruby-value str">""</span>)
477 55: <span class="ruby-identifier">func_quotes</span> = <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">"params"</span>].<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">/('|")/</span>)
479 57: <span class="ruby-identifier">func_quotes</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">item</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
480 58: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">item</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/'|"/</span>)
481 59: <span class="ruby-identifier">func_quotes</span>.<span class="ruby-identifier">delete_at</span>(<span class="ruby-identifier">i</span>)
482 60: <span class="ruby-keyword kw">break</span>
483 61: <span class="ruby-keyword kw">end</span>
484 62: <span class="ruby-keyword kw">end</span>
486 64: <span class="ruby-identifier">func_quotes</span>.<span class="ruby-identifier">reverse</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">item</span>,<span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
487 65: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">item</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/'|"/</span>)
488 66: <span class="ruby-identifier">func_quotes</span>.<span class="ruby-identifier">delete_at</span>(<span class="ruby-identifier">func_quotes</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>)
489 67: <span class="ruby-keyword kw">break</span>
490 68: <span class="ruby-keyword kw">end</span>
491 69: <span class="ruby-keyword kw">end</span>
493 71: <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">"params"</span>] = <span class="ruby-identifier">func_quotes</span>.<span class="ruby-identifier">join</span>
494 72: <span class="ruby-keyword kw">end</span>
496 74: <span class="ruby-identifier">func_hash</span>
497 75: <span class="ruby-keyword kw">end</span></pre>
506 <div id="eval-compound-fstatement-method" class="method-detail ">
507 <a name="M000059"></a>
509 <div class="method-heading">
511 <span class="method-name">eval_compound_fstatement</span><span
512 class="method-args">(function_hash)</span>
513 <span class="method-click-advice">click to toggle source</span>
517 <div class="method-description">
520 Returns the result of an evaluated compound statement that includes a
526 <div class="method-source-code"
527 id="eval-compound-fstatement-source">
529 <span class="ruby-comment cmt"># File lib/mcollective/matcher.rb, line 135</span>
530 135: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">eval_compound_fstatement</span>(<span class="ruby-identifier">function_hash</span>)
531 136: <span class="ruby-identifier">l_compare</span> = <span class="ruby-identifier">execute_function</span>(<span class="ruby-identifier">function_hash</span>)
533 138: <span class="ruby-comment cmt"># Break out early and return false if the function returns nil</span>
534 139: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">l_compare</span>
536 141: <span class="ruby-comment cmt"># Prevent unwanted discovery by limiting comparison operators</span>
537 142: <span class="ruby-comment cmt"># on Strings and Booleans</span>
538 143: <span class="ruby-keyword kw">if</span>((<span class="ruby-identifier">l_compare</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">l_compare</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">TrueClass</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">l_compare</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">FalseClass</span>)) <span class="ruby-operator">&&</span> <span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">"operator"</span>].<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/<|>/</span>))
539 144: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span> <span class="ruby-node">"Cannot do > and < comparison on Booleans and Strings '#{l_compare} #{function_hash["operator"]} #{function_hash["r_compare"]}'"</span>
540 145: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
541 146: <span class="ruby-keyword kw">end</span>
543 148: <span class="ruby-comment cmt"># Prevent backticks in function parameters</span>
544 149: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">"params"</span>] <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/`/</span>
545 150: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-value str">"Cannot use backticks in function parameters"</span>)
546 151: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
547 152: <span class="ruby-keyword kw">end</span>
549 154: <span class="ruby-comment cmt"># Escape strings for evaluation</span>
550 155: <span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">"r_compare"</span>] = <span class="ruby-node">"\"#{function_hash["r_compare"]}\""</span> <span class="ruby-keyword kw">if</span>(<span class="ruby-identifier">l_compare</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>) <span class="ruby-operator">&&</span> <span class="ruby-operator">!</span>(<span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">"operator"</span>] <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/=~|!=~/</span>))
552 157: <span class="ruby-comment cmt"># Do a regex comparison if right compare string is a regex</span>
553 158: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">"operator"</span>] <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/(=~|!=~)/</span>
554 159: <span class="ruby-comment cmt"># Fail if left compare value isn't a string</span>
555 160: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">l_compare</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>)
556 161: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-value str">"Cannot do a regex check on a non string value."</span>)
557 162: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
558 163: <span class="ruby-keyword kw">else</span>
559 164: <span class="ruby-identifier">compare_result</span> = <span class="ruby-identifier">l_compare</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">"r_compare"</span>])
560 165: <span class="ruby-comment cmt"># Flip return value for != operator</span>
561 166: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">"operator"</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">"!=~"</span>
562 167: <span class="ruby-operator">!</span>((<span class="ruby-identifier">compare_result</span>.<span class="ruby-identifier">nil?</span>) <span class="ruby-operator">?</span> <span class="ruby-keyword kw">false</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">true</span>)
563 168: <span class="ruby-keyword kw">else</span>
564 169: (<span class="ruby-identifier">compare_result</span>.<span class="ruby-identifier">nil?</span>) <span class="ruby-operator">?</span> <span class="ruby-keyword kw">false</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">true</span>
565 170: <span class="ruby-keyword kw">end</span>
566 171: <span class="ruby-keyword kw">end</span>
567 172: <span class="ruby-comment cmt"># Otherwise evaluate the logical comparison</span>
568 173: <span class="ruby-keyword kw">else</span>
569 174: <span class="ruby-identifier">l_compare</span> = <span class="ruby-node">"\"#{l_compare}\""</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">l_compare</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>)
570 175: <span class="ruby-identifier">result</span> = <span class="ruby-identifier">eval</span>(<span class="ruby-node">"#{l_compare} #{function_hash["operator"]} #{function_hash["r_compare"]}"</span>)
571 176: (<span class="ruby-identifier">result</span>.<span class="ruby-identifier">nil?</span>) <span class="ruby-operator">?</span> <span class="ruby-keyword kw">false</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">result</span>
572 177: <span class="ruby-keyword kw">end</span>
573 178: <span class="ruby-keyword kw">end</span></pre>
582 <div id="eval-compound-statement-method" class="method-detail ">
583 <a name="M000054"></a>
585 <div class="method-heading">
587 <span class="method-name">eval_compound_statement</span><span
588 class="method-args">(expression)</span>
589 <span class="method-click-advice">click to toggle source</span>
593 <div class="method-description">
596 Evaluates a compound statement
601 <div class="method-source-code"
602 id="eval-compound-statement-source">
604 <span class="ruby-comment cmt"># File lib/mcollective/matcher.rb, line 115</span>
605 115: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">eval_compound_statement</span>(<span class="ruby-identifier">expression</span>)
606 116: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">expression</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^\//</span>
607 117: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Util</span>.<span class="ruby-identifier">has_cf_class?</span>(<span class="ruby-identifier">expression</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span>)
608 118: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">expression</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/>=|<=|=|<|>/</span>
609 119: <span class="ruby-identifier">optype</span> = <span class="ruby-identifier">expression</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/>=|<=|=|<|>/</span>)
610 120: <span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span> = <span class="ruby-identifier">expression</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">split</span>(<span class="ruby-identifier">optype</span>[<span class="ruby-value">0</span>])
611 121: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">""</span>)[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">"/"</span>
612 122: <span class="ruby-identifier">optype</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">"="</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">optype</span> = <span class="ruby-value str">"=="</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">optype</span> = <span class="ruby-identifier">optype</span>[<span class="ruby-value">0</span>]
613 123: <span class="ruby-keyword kw">else</span>
614 124: <span class="ruby-identifier">optype</span> = <span class="ruby-value str">"=~"</span>
615 125: <span class="ruby-keyword kw">end</span>
617 127: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Util</span>.<span class="ruby-identifier">has_fact?</span>(<span class="ruby-identifier">name</span>,<span class="ruby-identifier">value</span>, <span class="ruby-identifier">optype</span>).<span class="ruby-identifier">to_s</span>
618 128: <span class="ruby-keyword kw">else</span>
619 129: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Util</span>.<span class="ruby-identifier">has_cf_class?</span>(<span class="ruby-identifier">expression</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span>)
620 130: <span class="ruby-keyword kw">end</span>
621 131: <span class="ruby-keyword kw">end</span></pre>
630 <div id="execute-function-method" class="method-detail ">
631 <a name="M000053"></a>
633 <div class="method-heading">
635 <span class="method-name">execute_function</span><span
636 class="method-args">(function_hash)</span>
637 <span class="method-click-advice">click to toggle source</span>
641 <div class="method-description">
644 Returns the result of an executed function
649 <div class="method-source-code"
650 id="execute-function-source">
652 <span class="ruby-comment cmt"># File lib/mcollective/matcher.rb, line 78</span>
653 78: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">execute_function</span>(<span class="ruby-identifier">function_hash</span>)
654 79: <span class="ruby-comment cmt"># In the case where a data plugin isn't present there are two ways we can handle</span>
655 80: <span class="ruby-comment cmt"># the raised exception. The function result can either be false or the entire</span>
656 81: <span class="ruby-comment cmt"># expression can fail.</span>
657 82: <span class="ruby-comment cmt">#</span>
658 83: <span class="ruby-comment cmt"># In the case where we return the result as false it opens us op to unexpected</span>
659 84: <span class="ruby-comment cmt"># negation behavior.</span>
660 85: <span class="ruby-comment cmt">#</span>
661 86: <span class="ruby-comment cmt"># !foo('bar').name = bar</span>
662 87: <span class="ruby-comment cmt">#</span>
663 88: <span class="ruby-comment cmt"># In this case the user would expect discovery to match on all machines where</span>
664 89: <span class="ruby-comment cmt"># the name value of the foo function does not equal bar. If a non existent function</span>
665 90: <span class="ruby-comment cmt"># returns false then it is posible to match machines where the name value of the</span>
666 91: <span class="ruby-comment cmt"># foo function is bar.</span>
667 92: <span class="ruby-comment cmt">#</span>
668 93: <span class="ruby-comment cmt"># Instead we raise a DDLValidationError to prevent this unexpected behavior from</span>
669 94: <span class="ruby-comment cmt"># happening.</span>
671 96: <span class="ruby-identifier">result</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">"name"</span>], <span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">"params"</span>])
673 98: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">"value"</span>]
674 99: <span class="ruby-keyword kw">begin</span>
675 100: <span class="ruby-identifier">eval_result</span> = <span class="ruby-identifier">result</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">"value"</span>])
676 101: <span class="ruby-keyword kw">rescue</span>
677 102: <span class="ruby-comment cmt"># If data field has not been set we set the comparison result to nil</span>
678 103: <span class="ruby-identifier">eval_result</span> = <span class="ruby-keyword kw">nil</span>
679 104: <span class="ruby-keyword kw">end</span>
680 105: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">eval_result</span>
681 106: <span class="ruby-keyword kw">else</span>
682 107: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">result</span>
683 108: <span class="ruby-keyword kw">end</span>
684 109: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">NoMethodError</span>
685 110: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">"cannot execute discovery function '#{function_hash["name"]}'. data plugin not found"</span>)
686 111: <span class="ruby-identifier">raise</span> <span class="ruby-constant">DDLValidationError</span>
687 112: <span class="ruby-keyword kw">end</span></pre>
702 <div id="rdoc-debugging-section-dump" class="debugging-section">
704 <p>Disabled; run with --debug to generate this.</p>
708 <div id="validator-badges">
709 <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
710 <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
711 Rdoc Generator</a> 1.1.6</small>.</p>