<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title> Class: Elephas::Backends::Hash — Documentation by YARD 0.8.6.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"> hasFrames = window.top.frames.main ? true : false; relpath = '../../'; framesUrl = "../../frames.html#!" + escape(window.location.href); </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 id="header"> <div id="menu"> <a href="../../_index.html">Index (H)</a> » <span class='title'><span class='object_link'><a href="../../Elephas.html" title="Elephas (module)">Elephas</a></span></span> » <span class='title'><span class='object_link'><a href="../Backends.html" title="Elephas::Backends (module)">Backends</a></span></span> » <span class="title">Hash</span> <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div> </div> <div id="search"> <a class="full_list_link" id="class_list_link" href="../../class_list.html"> Class List </a> <a class="full_list_link" id="method_list_link" href="../../method_list.html"> Method List </a> <a class="full_list_link" id="file_list_link" href="../../file_list.html"> File List </a> </div> <div class="clear"></div> </div> <iframe id="search_frame"></iframe> <div id="content"><h1>Class: Elephas::Backends::Hash </h1> <dl class="box"> <dt class="r1">Inherits:</dt> <dd class="r1"> <span class="inheritName"><span class='object_link'><a href="Base.html" title="Elephas::Backends::Base (class)">Base</a></span></span> <ul class="fullTree"> <li>Object</li> <li class="next"><span class='object_link'><a href="Base.html" title="Elephas::Backends::Base (class)">Base</a></span></li> <li class="next">Elephas::Backends::Hash</li> </ul> <a href="#" class="inheritanceTree">show all</a> </dd> <dt class="r2 last">Defined in:</dt> <dd class="r2 last">lib/elephas/backends/hash.rb</dd> </dl> <div class="clear"></div> <h2>Overview</h2><div class="docstring"> <div class="discussion"> <p>This is a simple backend, which uses an hash for storing the values.</p> </div> </div> <div class="tags"> </div> <h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2> <ul class="summary"> <li class="public "> <span class="summary_signature"> <a href="#data-instance_method" title="#data (instance method)">- (HashWithIndifferentAccess) <strong>data</strong> </a> </span> <span class="summary_desc"><div class='inline'><p>The internal hash used by the backend.</p> </div></span> </li> </ul> <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="#delete-instance_method" title="#delete (instance method)">- (Boolean) <strong>delete</strong>(key) </a> </span> <span class="summary_desc"><div class='inline'><p>Deletes a value from the cache.</p> </div></span> </li> <li class="public "> <span class="summary_signature"> <a href="#exists%3F-instance_method" title="#exists? (instance method)">- (Boolean) <strong>exists?</strong>(key) </a> </span> <span class="summary_desc"><div class='inline'><p>Checks if a key exists in the cache.</p> </div></span> </li> <li class="public "> <span class="summary_signature"> <a href="#initialize-instance_method" title="#initialize (instance method)">- (Hash) <strong>initialize</strong>(data = nil) </a> </span> <span class="note title constructor">constructor</span> <span class="summary_desc"><div class='inline'><p>Initialize the backend.</p> </div></span> </li> <li class="public "> <span class="summary_signature"> <a href="#read-instance_method" title="#read (instance method)">- (Entry|NilClass) <strong>read</strong>(key) </a> </span> <span class="summary_desc"><div class='inline'><p>Reads a value from the cache.</p> </div></span> </li> <li class="public "> <span class="summary_signature"> <a href="#write-instance_method" title="#write (instance method)">- (Object) <strong>write</strong>(key, value, options = {}) </a> </span> <span class="summary_desc"><div class='inline'><p>Writes a value to the cache.</p> </div></span> </li> </ul> <h3 class="inherited">Methods inherited from <span class='object_link'><a href="Base.html" title="Elephas::Backends::Base (class)">Base</a></span></h3> <p class="inherited"><span class='object_link'><a href="Base.html#now-instance_method" title="Elephas::Backends::Base#now (method)">#now</a></span></p> <div id="constructor_details" class="method_details_list"> <h2>Constructor Details</h2> <div class="method_details first"> <h3 class="signature first" id="initialize-instance_method"> - (<tt><span class='object_link'><a href="" title="Elephas::Backends::Hash (class)">Hash</a></span></tt>) <strong>initialize</strong>(data = nil) </h3><div class="docstring"> <div class="discussion"> <p>Initialize the backend.</p> </div> </div> <div class="tags"> <p class="tag_title">Parameters:</p> <ul class="param"> <li> <span class='name'>data</span> <span class='type'>(<tt><span class='object_link'><a href="" title="Elephas::Backends::Hash (class)">Hash</a></span></tt>)</span> <em class="default">(defaults to: <tt>nil</tt>)</em> — <div class='inline'><p>The initial data stored.</p> </div> </li> </ul> </div><table class="source_code"> <tr> <td> <pre class="lines"> 19 20 21</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/elephas/backends/hash.rb', line 19</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span> <span class='ivar'>@data</span> <span class='op'>=</span> <span class='id identifier rubyid_data'>data</span><span class='period'>.</span><span class='id identifier rubyid_ensure_hash'>ensure_hash</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with_indifferent_access'>with_indifferent_access</span> <span class='kw'>end</span></pre> </td> </tr> </table> </div> </div> <div id="instance_attr_details" class="attr_details"> <h2>Instance Attribute Details</h2> <span id="data=-instance_method"></span> <div class="method_details first"> <h3 class="signature first" id="data-instance_method"> - (<tt>HashWithIndifferentAccess</tt>) <strong>data</strong> </h3><div class="docstring"> <div class="discussion"> <p>The internal hash used by the backend.</p> </div> </div> <div class="tags"> <p class="tag_title">Returns:</p> <ul class="return"> <li> <span class='type'>(<tt>HashWithIndifferentAccess</tt>)</span> — <div class='inline'><p>The internal hash used by the backend.</p> </div> </li> </ul> </div><table class="source_code"> <tr> <td> <pre class="lines"> 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/elephas/backends/hash.rb', line 13</span> <span class='kw'>class</span> <span class='const'>Hash</span> <span class='op'><</span> <span class='const'>Base</span> <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:data</span> <span class='comment'># Initialize the backend. </span> <span class='comment'># </span> <span class='comment'># @param data [Hash] The initial data stored. </span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span> <span class='ivar'>@data</span> <span class='op'>=</span> <span class='id identifier rubyid_data'>data</span><span class='period'>.</span><span class='id identifier rubyid_ensure_hash'>ensure_hash</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with_indifferent_access'>with_indifferent_access</span> <span class='kw'>end</span> <span class='comment'># Reads a value from the cache. </span> <span class='comment'># </span> <span class='comment'># @param key [String] The key to lookup. </span> <span class='comment'># @return [Entry|NilClass] The read value or `nil`. </span> <span class='kw'>def</span> <span class='id identifier rubyid_read'>read</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span> <span class='id identifier rubyid_exists?'>exists?</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='ivar'>@data</span><span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='rbracket'>]</span> <span class='op'>:</span> <span class='kw'>nil</span> <span class='kw'>end</span> <span class='comment'># Writes a value to the cache. </span> <span class='comment'># </span> <span class='comment'># @param key [String] The key to associate the value with. </span> <span class='comment'># @param value [Object] The value to write. Setting a value to `nil` **doesn't** mean *deleting* the value. </span> <span class='comment'># @param options [Hash] A list of options for writing. </span> <span class='comment'># @see Elephas::Cache.setup_options </span> <span class='comment'># @return [Object] The value itself. </span> <span class='kw'>def</span> <span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='id identifier rubyid_entry'>entry</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Elephas</span><span class='op'>::</span><span class='const'>Entry</span><span class='period'>.</span><span class='id identifier rubyid_ensure'>ensure</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span> <span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_refresh'>refresh</span> <span class='ivar'>@data</span><span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_entry'>entry</span> <span class='id identifier rubyid_entry'>entry</span> <span class='kw'>end</span> <span class='comment'># Deletes a value from the cache. </span> <span class='comment'># </span> <span class='comment'># @param key [String] The key to delete. </span> <span class='comment'># @return [Boolean] `true` if the key was in the cache, `false` otherwise. </span> <span class='kw'>def</span> <span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span> <span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='ivar'>@data</span><span class='period'>.</span><span class='id identifier rubyid_has_key?'>has_key?</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span> <span class='ivar'>@data</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span> <span class='id identifier rubyid_rv'>rv</span> <span class='kw'>end</span> <span class='comment'># Checks if a key exists in the cache. </span> <span class='comment'># </span> <span class='comment'># @param key [String] The key to lookup. </span> <span class='comment'># @return [Boolean] `true` if the key is in the cache, `false` otherwise. </span> <span class='kw'>def</span> <span class='id identifier rubyid_exists?'>exists?</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span> <span class='ivar'>@data</span><span class='period'>.</span><span class='id identifier rubyid_has_key?'>has_key?</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='ivar'>@data</span><span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_valid?'>valid?</span><span class='lparen'>(</span><span class='kw'>self</span><span class='rparen'>)</span> <span class='kw'>end</span> <span class='kw'>end</span></pre> </td> </tr> </table> </div> </div> <div id="instance_method_details" class="method_details_list"> <h2>Instance Method Details</h2> <div class="method_details first"> <h3 class="signature first" id="delete-instance_method"> - (<tt>Boolean</tt>) <strong>delete</strong>(key) </h3><div class="docstring"> <div class="discussion"> <p>Deletes a value from the cache.</p> </div> </div> <div class="tags"> <p class="tag_title">Parameters:</p> <ul class="param"> <li> <span class='name'>key</span> <span class='type'>(<tt>String</tt>)</span> — <div class='inline'><p>The key to delete.</p> </div> </li> </ul> <p class="tag_title">Returns:</p> <ul class="return"> <li> <span class='type'>(<tt>Boolean</tt>)</span> — <div class='inline'><p><code>true</code> if the key was in the cache, <code>false</code> otherwise.</p> </div> </li> </ul> </div><table class="source_code"> <tr> <td> <pre class="lines"> 49 50 51 52 53</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/elephas/backends/hash.rb', line 49</span> <span class='kw'>def</span> <span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span> <span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='ivar'>@data</span><span class='period'>.</span><span class='id identifier rubyid_has_key?'>has_key?</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span> <span class='ivar'>@data</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span> <span class='id identifier rubyid_rv'>rv</span> <span class='kw'>end</span></pre> </td> </tr> </table> </div> <div class="method_details "> <h3 class="signature " id="exists?-instance_method"> - (<tt>Boolean</tt>) <strong>exists?</strong>(key) </h3><div class="docstring"> <div class="discussion"> <p>Checks if a key exists in the cache.</p> </div> </div> <div class="tags"> <p class="tag_title">Parameters:</p> <ul class="param"> <li> <span class='name'>key</span> <span class='type'>(<tt>String</tt>)</span> — <div class='inline'><p>The key to lookup.</p> </div> </li> </ul> <p class="tag_title">Returns:</p> <ul class="return"> <li> <span class='type'>(<tt>Boolean</tt>)</span> — <div class='inline'><p><code>true</code> if the key is in the cache, <code>false</code> otherwise.</p> </div> </li> </ul> </div><table class="source_code"> <tr> <td> <pre class="lines"> 59 60 61</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/elephas/backends/hash.rb', line 59</span> <span class='kw'>def</span> <span class='id identifier rubyid_exists?'>exists?</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span> <span class='ivar'>@data</span><span class='period'>.</span><span class='id identifier rubyid_has_key?'>has_key?</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='ivar'>@data</span><span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_valid?'>valid?</span><span class='lparen'>(</span><span class='kw'>self</span><span class='rparen'>)</span> <span class='kw'>end</span></pre> </td> </tr> </table> </div> <div class="method_details "> <h3 class="signature " id="read-instance_method"> - (<tt><span class='object_link'><a href="../Entry.html" title="Elephas::Entry (class)">Entry</a></span>|NilClass</tt>) <strong>read</strong>(key) </h3><div class="docstring"> <div class="discussion"> <p>Reads a value from the cache.</p> </div> </div> <div class="tags"> <p class="tag_title">Parameters:</p> <ul class="param"> <li> <span class='name'>key</span> <span class='type'>(<tt>String</tt>)</span> — <div class='inline'><p>The key to lookup.</p> </div> </li> </ul> <p class="tag_title">Returns:</p> <ul class="return"> <li> <span class='type'>(<tt><span class='object_link'><a href="../Entry.html" title="Elephas::Entry (class)">Entry</a></span>|NilClass</tt>)</span> — <div class='inline'><p>The read value or <code>nil</code>.</p> </div> </li> </ul> </div><table class="source_code"> <tr> <td> <pre class="lines"> 27 28 29</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/elephas/backends/hash.rb', line 27</span> <span class='kw'>def</span> <span class='id identifier rubyid_read'>read</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span> <span class='id identifier rubyid_exists?'>exists?</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='ivar'>@data</span><span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='rbracket'>]</span> <span class='op'>:</span> <span class='kw'>nil</span> <span class='kw'>end</span></pre> </td> </tr> </table> </div> <div class="method_details "> <h3 class="signature " id="write-instance_method"> - (<tt>Object</tt>) <strong>write</strong>(key, value, options = {}) </h3><div class="docstring"> <div class="discussion"> <p>Writes a value to the cache.</p> </div> </div> <div class="tags"> <p class="tag_title">Parameters:</p> <ul class="param"> <li> <span class='name'>key</span> <span class='type'>(<tt>String</tt>)</span> — <div class='inline'><p>The key to associate the value with.</p> </div> </li> <li> <span class='name'>value</span> <span class='type'>(<tt>Object</tt>)</span> — <div class='inline'><p>The value to write. Setting a value to <code>nil</code> <strong>doesn’t</strong> mean <em>deleting</em> the value.</p> </div> </li> <li> <span class='name'>options</span> <span class='type'>(<tt><span class='object_link'><a href="" title="Elephas::Backends::Hash (class)">Hash</a></span></tt>)</span> <em class="default">(defaults to: <tt>{}</tt>)</em> — <div class='inline'><p>A list of options for writing.</p> </div> </li> </ul> <p class="tag_title">Returns:</p> <ul class="return"> <li> <span class='type'>(<tt>Object</tt>)</span> — <div class='inline'><p>The value itself.</p> </div> </li> </ul> <p class="tag_title">See Also:</p> <ul class="see"> <li>Cache.setup_options</li> </ul> </div><table class="source_code"> <tr> <td> <pre class="lines"> 38 39 40 41 42 43</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/elephas/backends/hash.rb', line 38</span> <span class='kw'>def</span> <span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='id identifier rubyid_entry'>entry</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Elephas</span><span class='op'>::</span><span class='const'>Entry</span><span class='period'>.</span><span class='id identifier rubyid_ensure'>ensure</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span> <span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_refresh'>refresh</span> <span class='ivar'>@data</span><span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_entry'>entry</span> <span class='id identifier rubyid_entry'>entry</span> <span class='kw'>end</span></pre> </td> </tr> </table> </div> </div> </div> <div id="footer"> Generated on Thu May 23 11:05:50 2013 by <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> 0.8.6.1 (ruby-1.9.3). </div> </body> </html>