<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title> Class: Mocha::StateMachine — Mocha 1.11.1 </title> <link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" /> <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" /> <script type="text/javascript" charset="utf-8"> pathId = "Mocha::StateMachine"; relpath = '../'; </script> <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script> <script type="text/javascript" charset="utf-8" src="../js/app.js"></script> </head> <body> <div class="nav_wrap"> <iframe id="nav" src="../class_list.html?1"></iframe> <div id="resizer"></div> </div> <div id="main" tabindex="-1"> <div id="header"> <div id="menu"> <a href="../_index.html">Index (S)</a> » <span class='title'><span class='object_link'><a href="../Mocha.html" title="Mocha (module)">Mocha</a></span></span> » <span class="title">StateMachine</span> </div> <div id="search"> <a class="full_list_link" id="class_list_link" href="../class_list.html"> <svg width="24" height="24"> <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> </svg> </a> </div> <div class="clear"></div> </div> <div id="content"><h1>Class: Mocha::StateMachine </h1> <div class="box_info"> <dl> <dt>Inherits:</dt> <dd> <span class="inheritName"><span class='object_link'>Object</span></span> <ul class="fullTree"> <li><span class='object_link'>Object</span></li> <li class="next">Mocha::StateMachine</li> </ul> <a href="#" class="inheritanceTree">show all</a> </dd> </dl> <dl> <dt>Defined in:</dt> <dd>lib/mocha/state_machine.rb</dd> </dl> </div> <h2>Overview</h2><div class="docstring"> <div class="discussion"> <p>A state machine that is used to constrain the order of invocations. An invocation can be constrained to occur when a state <span class='object_link'><a href="#is-instance_method" title="Mocha::StateMachine#is (method)">#is</a></span>, or <span class='object_link'><a href="#is_not-instance_method" title="Mocha::StateMachine#is_not (method)">#is_not</a></span>, active.</p> </div> </div> <div class="tags"> </div><h2>Defined Under Namespace</h2> <p class="children"> <strong class="classes">Classes:</strong> <span class='object_link'><a href="StateMachine/State.html" title="Mocha::StateMachine::State (class)">State</a></span>, <span class='object_link'><a href="StateMachine/StatePredicate.html" title="Mocha::StateMachine::StatePredicate (class)">StatePredicate</a></span> </p> <h2> Instance Method Summary <small><a href="#" class="summary_toggle">collapse</a></small> </h2> <ul class="summary"> <li class="public "> <span class="summary_signature"> <a href="#become-instance_method" title="#become (instance method)">#<strong>become</strong>(next_state_name) ⇒ Object </a> </span> <span class="summary_desc"><div class='inline'> <p>Put the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">StateMachine</a></span> into the <code>next_state_name</code>.</p> </div></span> </li> <li class="public "> <span class="summary_signature"> <a href="#is-instance_method" title="#is (instance method)">#<strong>is</strong>(state_name) ⇒ State </a> </span> <span class="summary_desc"><div class='inline'> <p>Provides a mechanism to change the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">StateMachine</a></span> into the state specified by <code>state_name</code> at some point in the future.</p> </div></span> </li> <li class="public "> <span class="summary_signature"> <a href="#is_not-instance_method" title="#is_not (instance method)">#<strong>is_not</strong>(state_name) ⇒ Object </a> </span> <span class="summary_desc"><div class='inline'> <p>Provides a mechanism to determine whether the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">StateMachine</a></span> is not in the state specified by <code>state_name</code> at some point in the future.</p> </div></span> </li> <li class="public "> <span class="summary_signature"> <a href="#starts_as-instance_method" title="#starts_as (instance method)">#<strong>starts_as</strong>(initial_state_name) ⇒ StateMachine </a> </span> <span class="summary_desc"><div class='inline'> <p>Put the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">StateMachine</a></span> into the state specified by <code>initial_state_name</code>.</p> </div></span> </li> </ul> <div id="instance_method_details" class="method_details_list"> <h2>Instance Method Details</h2> <div class="method_details first"> <h3 class="signature first" id="become-instance_method"> #<strong>become</strong>(next_state_name) ⇒ <tt><span class='object_link'>Object</span></tt> </h3><div class="docstring"> <div class="discussion"> <p>Put the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> into the <code>next_state_name</code>.</p> </div> </div> <div class="tags"> <p class="tag_title">Parameters:</p> <ul class="param"> <li> <span class='name'>next_state_name</span> <span class='type'>(<tt>String</tt>)</span> — <div class='inline'> <p>name of new state</p> </div> </li> </ul> </div><table class="source_code"> <tr> <td> <pre class="lines"> 72 73 74</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/mocha/state_machine.rb', line 72</span> <span class='kw'>def</span> <span class='id identifier rubyid_become'>become</span><span class='lparen'>(</span><span class='id identifier rubyid_next_state_name'>next_state_name</span><span class='rparen'>)</span> <span class='ivar'>@current_state</span> <span class='op'>=</span> <span class='id identifier rubyid_next_state_name'>next_state_name</span> <span class='kw'>end</span></pre> </td> </tr> </table> </div> <div class="method_details "> <h3 class="signature " id="is-instance_method"> #<strong>is</strong>(state_name) ⇒ <tt><span class='object_link'><a href="StateMachine/State.html" title="Mocha::StateMachine::State (class)">State</a></span></tt> </h3><div class="docstring"> <div class="discussion"> <p>Provides a mechanism to change the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> into the state specified by <code>state_name</code> at some point in the future.</p> <p>Or provides a mechanism to determine whether the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> is in the state specified by <code>state_name</code> at some point in the future.</p> </div> </div> <div class="tags"> <p class="tag_title">Parameters:</p> <ul class="param"> <li> <span class='name'>state_name</span> <span class='type'>(<tt>String</tt>)</span> — <div class='inline'> <p>name of new state</p> </div> </li> </ul> <p class="tag_title">Returns:</p> <ul class="return"> <li> <span class='type'>(<tt><span class='object_link'><a href="StateMachine/State.html" title="Mocha::StateMachine::State (class)">State</a></span></tt>)</span> — <div class='inline'> <p>state which, when activated, will change the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> into the state with the specified <code>state_name</code>.</p> </div> </li> </ul> </div><table class="source_code"> <tr> <td> <pre class="lines"> 82 83 84</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/mocha/state_machine.rb', line 82</span> <span class='kw'>def</span> <span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='id identifier rubyid_state_name'>state_name</span><span class='rparen'>)</span> <span class='const'><span class='object_link'><a href="StateMachine/State.html" title="Mocha::StateMachine::State (class)">State</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='id identifier rubyid_state_name'>state_name</span><span class='rparen'>)</span> <span class='kw'>end</span></pre> </td> </tr> </table> </div> <div class="method_details "> <h3 class="signature " id="is_not-instance_method"> #<strong>is_not</strong>(state_name) ⇒ <tt><span class='object_link'>Object</span></tt> </h3><div class="docstring"> <div class="discussion"> <p>Provides a mechanism to determine whether the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> is not in the state specified by <code>state_name</code> at some point in the future. rubocop:disable Naming/PredicateName</p> </div> </div> <div class="tags"> </div><table class="source_code"> <tr> <td> <pre class="lines"> 88 89 90</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/mocha/state_machine.rb', line 88</span> <span class='kw'>def</span> <span class='id identifier rubyid_is_not'>is_not</span><span class='lparen'>(</span><span class='id identifier rubyid_state_name'>state_name</span><span class='rparen'>)</span> <span class='const'><span class='object_link'><a href="StateMachine/StatePredicate.html" title="Mocha::StateMachine::StatePredicate (class)">StatePredicate</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='id identifier rubyid_state_name'>state_name</span><span class='rparen'>)</span> <span class='kw'>end</span></pre> </td> </tr> </table> </div> <div class="method_details "> <h3 class="signature " id="starts_as-instance_method"> #<strong>starts_as</strong>(initial_state_name) ⇒ <tt><span class='object_link'><a href="" title="Mocha::StateMachine (class)">StateMachine</a></span></tt> </h3><div class="docstring"> <div class="discussion"> <p>Put the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> into the state specified by <code>initial_state_name</code>.</p> </div> </div> <div class="tags"> <p class="tag_title">Parameters:</p> <ul class="param"> <li> <span class='name'>initial_state_name</span> <span class='type'>(<tt>String</tt>)</span> — <div class='inline'> <p>name of initial state</p> </div> </li> </ul> <p class="tag_title">Returns:</p> <ul class="return"> <li> <span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::StateMachine (class)">StateMachine</a></span></tt>)</span> — <div class='inline'> <p>state machine, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> methods to be chained.</p> </div> </li> </ul> </div><table class="source_code"> <tr> <td> <pre class="lines"> 64 65 66 67</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/mocha/state_machine.rb', line 64</span> <span class='kw'>def</span> <span class='id identifier rubyid_starts_as'>starts_as</span><span class='lparen'>(</span><span class='id identifier rubyid_initial_state_name'>initial_state_name</span><span class='rparen'>)</span> <span class='id identifier rubyid_become'>become</span><span class='lparen'>(</span><span class='id identifier rubyid_initial_state_name'>initial_state_name</span><span class='rparen'>)</span> <span class='kw'>self</span> <span class='kw'>end</span></pre> </td> </tr> </table> </div> </div> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-625523-7"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-625523-7'); </script> </div> <div id="footer"> Generated on Tue Dec 17 12:49:36 2019 by <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> 0.9.20 (ruby-2.6.5). </div> </div> </body> </html>