tmud-3.0.0/benchmark/
tmud-3.0.0/cmd/
tmud-3.0.0/cmd/objects/
tmud-3.0.0/cmd/tiny/
tmud-3.0.0/doc/SQLite/
tmud-3.0.0/doc/SQLite3/
tmud-3.0.0/doc/TernaryTrie/
tmud-3.0.0/farts/
tmud-3.0.0/lib/
tmud-3.0.0/lib/engine/
tmud-3.0.0/lib/farts/
tmud-3.0.0/logs/
<!DOCTYPE html>

<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">

<title>module Publisher - TeensyMUD 3.0.0 Mud Server</title>

<link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
</script>

<script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>


<body id="top" class="module">
<nav id="metadata">
  <nav id="home-section" class="section">
  <h3 class="section-header">
    <a href="./index.html">Home</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </h3>
</nav>


  <nav id="search-section" class="section project-section" class="initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <h3 class="section-header">
      <input type="text" name="search" placeholder="Search" id="search-field"
             title="Type to search, Up and Down to navigate, Enter to load">
    </h3>
  </form>

  <ul id="search-results" class="initially-hidden"></ul>
</nav>


  <div id="file-metadata">
    <nav id="file-list-section" class="section">
  <h3 class="section-header">Defined In</h3>
  <ul>
    <li>lib/utility/publisher.rb
  </ul>
</nav>

    
  </div>

  <div id="class-metadata">
    
    
    
    <!-- Method Quickref -->
<nav id="method-list-section" class="section">
  <h3 class="section-header">Methods</h3>

  <ul class="link-list">
    
    <li><a href="#method-i-publish">#publish</a>
    
    <li><a href="#method-i-subscribe">#subscribe</a>
    
    <li><a href="#method-i-subscriber_count">#subscriber_count</a>
    
    <li><a href="#method-i-unsubscribe">#unsubscribe</a>
    
    <li><a href="#method-i-unsubscribe_all">#unsubscribe_all</a>
    
  </ul>
</nav>

  </div>

  <div id="project-metadata">
    <nav id="fileindex-section" class="section project-section">
  <h3 class="section-header">Pages</h3>

  <ul>
  
    <li class="file"><a href="./README.html">README</a>
  
    <li class="file"><a href="./TML.html">TML</a>
  
  </ul>
</nav>

    <nav id="classindex-section" class="section project-section">
  <h3 class="section-header">Class and Module Index</h3>

  <ul class="link-list">
  
    <li><a href="./Farts.html">Farts</a>
  
    <li><a href="./Farts/AttributeSyntaxNode.html">Farts::AttributeSyntaxNode</a>
  
    <li><a href="./Farts/CallSyntaxNode.html">Farts::CallSyntaxNode</a>
  
    <li><a href="./Farts/CommandSyntaxNode.html">Farts::CommandSyntaxNode</a>
  
    <li><a href="./Farts/CommentSyntaxNode.html">Farts::CommentSyntaxNode</a>
  
    <li><a href="./Farts/EndSyntaxNode.html">Farts::EndSyntaxNode</a>
  
    <li><a href="./Farts/IfSyntaxNode.html">Farts::IfSyntaxNode</a>
  
    <li><a href="./Farts/Interpreter.html">Farts::Interpreter</a>
  
    <li><a href="./Farts/Lexer.html">Farts::Lexer</a>
  
    <li><a href="./Farts/Lib.html">Farts::Lib</a>
  
    <li><a href="./Farts/LiteralSyntaxNode.html">Farts::LiteralSyntaxNode</a>
  
    <li><a href="./Farts/LocalVarSyntaxNode.html">Farts::LocalVarSyntaxNode</a>
  
    <li><a href="./Farts/Parser.html">Farts::Parser</a>
  
    <li><a href="./Farts/ProgramSyntaxNode.html">Farts::ProgramSyntaxNode</a>
  
    <li><a href="./Farts/SyntaxNode.html">Farts::SyntaxNode</a>
  
    <li><a href="./SQLite.html">SQLite</a>
  
    <li><a href="./SQLite3.html">SQLite3</a>
  
    <li><a href="./SQLite3/Database.html">SQLite3::Database</a>
  
    <li><a href="./SQLite/Database.html">SQLite::Database</a>
  
    <li><a href="./TernaryTrie.html">TernaryTrie</a>
  
    <li><a href="./TernaryTrie/TNode.html">TernaryTrie::TNode</a>
  
    <li><a href="./ASCIICodes.html">ASCIICodes</a>
  
    <li><a href="./Acceptor.html">Acceptor</a>
  
    <li><a href="./Account.html">Account</a>
  
    <li><a href="./BoolExpParser.html">BoolExpParser</a>
  
    <li><a href="./CacheEntry.html">CacheEntry</a>
  
    <li><a href="./CacheManager.html">CacheManager</a>
  
    <li><a href="./CacheStats.html">CacheStats</a>
  
    <li><a href="./Character.html">Character</a>
  
    <li><a href="./Client.html">Client</a>
  
    <li><a href="./Cmd.html">Cmd</a>
  
    <li><a href="./ColorFilter.html">ColorFilter</a>
  
    <li><a href="./Command.html">Command</a>
  
    <li><a href="./Configuration.html">Configuration</a>
  
    <li><a href="./Connection.html">Connection</a>
  
    <li><a href="./Connector.html">Connector</a>
  
    <li><a href="./ConsoleClient.html">ConsoleClient</a>
  
    <li><a href="./CursesClient.html">CursesClient</a>
  
    <li><a href="./DbmStore.html">DbmStore</a>
  
    <li><a href="./DebugFilter.html">DebugFilter</a>
  
    <li><a href="./Dumper.html">Dumper</a>
  
    <li><a href="./Engine.html">Engine</a>
  
    <li><a href="./Event.html">Event</a>
  
    <li><a href="./EventManager.html">EventManager</a>
  
    <li><a href="./Exit.html">Exit</a>
  
    <li><a href="./Filter.html">Filter</a>
  
    <li><a href="./GameObject.html">GameObject</a>
  
    <li><a href="./GdbmStore.html">GdbmStore</a>
  
    <li><a href="./LineIO.html">LineIO</a>
  
    <li><a href="./Loader.html">Loader</a>
  
    <li><a href="./Log.html">Log</a>
  
    <li><a href="./Module.html">Module</a>
  
    <li><a href="./Obj.html">Obj</a>
  
    <li><a href="./ObjCmd.html">ObjCmd</a>
  
    <li><a href="./Object.html">Object</a>
  
    <li><a href="./PacketIO.html">PacketIO</a>
  
    <li><a href="./ProtocolStack.html">ProtocolStack</a>
  
    <li><a href="./Publisher.html">Publisher</a>
  
    <li><a href="./Reactor.html">Reactor</a>
  
    <li><a href="./Room.html">Room</a>
  
    <li><a href="./Root.html">Root</a>
  
    <li><a href="./Script.html">Script</a>
  
    <li><a href="./SdbmStore.html">SdbmStore</a>
  
    <li><a href="./Session.html">Session</a>
  
    <li><a href="./SockIO.html">SockIO</a>
  
    <li><a href="./Sqlite3Store.html">Sqlite3Store</a>
  
    <li><a href="./SqliteStore.html">SqliteStore</a>
  
    <li><a href="./Store.html">Store</a>
  
    <li><a href="./String.html">String</a>
  
    <li><a href="./TelnetCodes.html">TelnetCodes</a>
  
    <li><a href="./TelnetFilter.html">TelnetFilter</a>
  
    <li><a href="./TerminalFilter.html">TerminalFilter</a>
  
    <li><a href="./Timer.html">Timer</a>
  
    <li><a href="./Utility.html">Utility</a>
  
    <li><a href="./VT100Codes.html">VT100Codes</a>
  
    <li><a href="./World.html">World</a>
  
    <li><a href="./XmlStore.html">XmlStore</a>
  
    <li><a href="./YamlStore.html">YamlStore</a>
  
  </ul>
</nav>

  </div>
</nav>

<div id="documentation">
  <h1 class="module">module Publisher</h1>

  <div id="description" class="description">
    
<p><a href="Publisher.html">Publisher</a> is a variation on Ruby's Observable.
We do not keep track of any changed state; instead we assume that by virtue
of calling publish we have changed state.  We do not allow serialization of
subscribers. We allow a <a href="Publisher.html">Publisher</a> to have
multiple publications and maintain separate lists of subscribers for each
one.</p>

  </div><!-- description -->

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    

    

    <!-- Methods -->
    
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Public Instance Methods</h3>

    
      <div id="method-i-publish" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">publish</span><span
            class="method-args">(*arg)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>If this object’s changed state is <code>true</code>, invoke the update
method in each currently associated subscriber in turn, passing it the
given arguments. The changed state is then set to <code>false</code>.</p>
          

          
          <div class="method-source-code" id="publish-source">
            <pre><span class="ruby-comment"># File lib/utility/publisher.rb, line 65</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">publish</span>(*<span class="ruby-identifier">arg</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-keyword">defined?</span> <span class="ruby-ivar">@subscribers</span>
    <span class="ruby-ivar">@subscribers</span>.<span class="ruby-identifier">dup</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:to_int</span>)
        <span class="ruby-constant">Engine</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">db</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">s</span>).<span class="ruby-identifier">update</span>(*<span class="ruby-identifier">arg</span>)
      <span class="ruby-keyword">else</span>
        <span class="ruby-identifier">s</span>.<span class="ruby-identifier">update</span>(*<span class="ruby-identifier">arg</span>)
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- publish-source -->
          
        </div>

        

        
      </div><!-- publish-method -->

    
      <div id="method-i-subscribe" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">subscribe</span><span
            class="method-args">(subscriber)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Add <code>subscriber</code> as an subscriber on this object.
<code>subscriber</code> will now receive notifications.</p>
          

          
          <div class="method-source-code" id="subscribe-source">
            <pre><span class="ruby-comment"># File lib/utility/publisher.rb, line 30</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">subscribe</span>(<span class="ruby-identifier">subscriber</span>)
  <span class="ruby-ivar">@subscribers</span> <span class="ruby-operator">||=</span> []
  <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">subscriber</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:to_int</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">subscriber</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:update</span>)
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">NoMethodError</span>, <span class="ruby-string">&quot;subscriber needs to respond to 'update'&quot;</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-ivar">@subscribers</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">subscriber</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- subscribe-source -->
          
        </div>

        

        
      </div><!-- subscribe-method -->

    
      <div id="method-i-subscriber_count" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">subscriber_count</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Count of subscribers to this object.</p>
          

          
          <div class="method-source-code" id="subscriber_count-source">
            <pre><span class="ruby-comment"># File lib/utility/publisher.rb, line 56</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">subscriber_count</span>
  <span class="ruby-ivar">@subscribers</span> <span class="ruby-operator">?</span> <span class="ruby-ivar">@subscribers</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">:</span> <span class="ruby-value">0</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- subscriber_count-source -->
          
        </div>

        

        
      </div><!-- subscriber_count-method -->

    
      <div id="method-i-unsubscribe" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">unsubscribe</span><span
            class="method-args">(subscriber)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Delete <code>subscriber</code> as a subscriber on this object. It will no
longer receive notifications.</p>
          

          
          <div class="method-source-code" id="unsubscribe-source">
            <pre><span class="ruby-comment"># File lib/utility/publisher.rb, line 42</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">unsubscribe</span>(<span class="ruby-identifier">subscriber</span>)
  <span class="ruby-ivar">@subscribers</span>.<span class="ruby-identifier">delete</span> <span class="ruby-identifier">subscriber</span> <span class="ruby-keyword">if</span> <span class="ruby-keyword">defined?</span> <span class="ruby-ivar">@subscribers</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- unsubscribe-source -->
          
        </div>

        

        
      </div><!-- unsubscribe-method -->

    
      <div id="method-i-unsubscribe_all" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">unsubscribe_all</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Delete all subscribers associated with this object.</p>
          

          
          <div class="method-source-code" id="unsubscribe_all-source">
            <pre><span class="ruby-comment"># File lib/utility/publisher.rb, line 49</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">unsubscribe_all</span>
  <span class="ruby-ivar">@subscribers</span>.<span class="ruby-identifier">clear</span> <span class="ruby-keyword">if</span> <span class="ruby-keyword">defined?</span> <span class="ruby-ivar">@subscribers</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- unsubscribe_all-source -->
          
        </div>

        

        
      </div><!-- unsubscribe_all-method -->

    
    </section><!-- public-instance-method-details -->
  
  </section><!-- 5Buntitled-5D -->

</div><!-- documentation -->


<footer id="validator-badges">
  <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
  <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.1.
  <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
</footer>