docs/Lazier/Hash.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Module: Lazier::Hash
— Documentation by YARD 0.9.5
</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 = "Lazier::Hash";
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"></iframe>
<div id="resizer"></div>
</div>
<div id="main" tabindex="-1">
<div id="header">
<div id="menu">
<a href="../_index.html">Index (H)</a> »
<span class='title'><span class='object_link'><a href="../Lazier.html" title="Lazier (module)">Lazier</a></span></span>
»
<span class="title">Hash</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>
<iframe id="search_frame" src="../class_list.html"></iframe>
<div id="content"><h1>Module: Lazier::Hash
</h1>
<div class="box_info">
<dl>
<dt>Extended by:</dt>
<dd>ActiveSupport::Concern</dd>
</dl>
<dl>
<dt>Defined in:</dt>
<dd>lib/lazier/hash.rb</dd>
</dl>
</div>
<h2>Overview</h2><div class="docstring">
<div class="discussion">
<p>Extensions for <code>Hash</code> objects.</p>
</div>
</div>
<div class="tags">
</div>
<h2>Constant Summary</h2>
<dl class="constants">
<dt id="VALID_ACCESSES-constant" class="">VALID_ACCESSES =
<div class="docstring">
<div class="discussion">
<p>The supported accesses for #ensure_access</p>
</div>
</div>
<div class="tags">
</div>
</dt>
<dd><pre class="code"><span class='lbrace'>{</span>
<span class='label'>strings:</span> <span class='symbol'>:stringify_keys</span><span class='comma'>,</span>
<span class='label'>symbols:</span> <span class='symbol'>:symbolize_keys</span><span class='comma'>,</span>
<span class='label'>indifferent:</span> <span class='symbol'>:with_indifferent_access</span><span class='comma'>,</span>
<span class='label'>dotted:</span> <span class='symbol'>:enable_dotted_access</span>
<span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span></pre></dd>
</dl>
<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="#compact-instance_method" title="#compact (instance method)">#<strong>compact</strong>(&validator) ⇒ Hash </a>
</span>
<span class="summary_desc"><div class='inline'><p>Returns a new hash, removing all keys which values are blank.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#compact%21-instance_method" title="#compact! (instance method)">#<strong>compact!</strong>(&validator) ⇒ Object </a>
</span>
<span class="summary_desc"><div class='inline'><p>Compacts the current hash, removing all keys which values are blank.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#enable_dotted_access-instance_method" title="#enable_dotted_access (instance method)">#<strong>enable_dotted_access</strong>(readonly = true) ⇒ Hash </a>
</span>
<span class="summary_desc"><div class='inline'><p>Makes sure that the hash is accessible using dotted notation.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#ensure_access-instance_method" title="#ensure_access (instance method)">#<strong>ensure_access</strong>(*accesses) ⇒ Hash </a>
</span>
<span class="summary_desc"><div class='inline'><p>Makes sure that the keys of the hash are accessible in the desired way.</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="compact-instance_method">
#<strong>compact</strong>(&validator) ⇒ <tt><span class='object_link'><a href="" title="Lazier::Hash (module)">Hash</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Returns a new hash, removing all keys which values are blank.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>validator</span>
<span class='type'>(<tt>Proc</tt>)</span>
—
<div class='inline'><p>If present all the keys which evaluates to true will be removed. Otherwise all blank values will be removed.</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="Lazier::Hash (module)">Hash</a></span></tt>)</span>
—
<div class='inline'><p>The hash with all blank values removed.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
23
24
25</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/lazier/hash.rb', line 23</span>
<span class='kw'>def</span> <span class='id identifier rubyid_compact'>compact</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_validator'>validator</span><span class='rparen'>)</span>
<span class='id identifier rubyid_dup'>dup</span><span class='period'>.</span><span class='id identifier rubyid_compact!'>compact!</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_validator'>validator</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="compact!-instance_method">
#<strong>compact!</strong>(&validator) ⇒ <tt><span class='object_link'><a href="Object.html" title="Lazier::Object (module)">Object</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Compacts the current hash, removing all keys which values are blank.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>validator</span>
<span class='type'>(<tt>Proc</tt>)</span>
—
<div class='inline'><p>If present all the keys which evaluates to true will be removed. Otherwise all blank values will be removed.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
30
31
32
33</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/lazier/hash.rb', line 30</span>
<span class='kw'>def</span> <span class='id identifier rubyid_compact!'>compact!</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_validator'>validator</span><span class='rparen'>)</span>
<span class='id identifier rubyid_validator'>validator</span> <span class='op'>||=</span> <span class='tlambda'>-></span><span class='lparen'>(</span><span class='id identifier rubyid__'>_</span><span class='comma'>,</span> <span class='id identifier rubyid_v'>v</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_v'>v</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='rbrace'>}</span>
<span class='id identifier rubyid_reject!'>reject!</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_validator'>validator</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="enable_dotted_access-instance_method">
#<strong>enable_dotted_access</strong>(readonly = true) ⇒ <tt><span class='object_link'><a href="" title="Lazier::Hash (module)">Hash</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Makes sure that the hash is accessible using dotted notation. This is also applied to every embedded hash.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>readonly</span>
<span class='type'>(<tt><span class='object_link'><a href="Boolean.html" title="Lazier::Boolean (module)">Boolean</a></span></tt>)</span>
<em class="default">(defaults to: <tt>true</tt>)</em>
—
<div class='inline'><p>If the dotted notation is only enable for reading. <code>true</code> by default.</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="Lazier::Hash (module)">Hash</a></span></tt>)</span>
—
<div class='inline'><p>The current hash with keys enabled for dotted access.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
48
49
50
51
52
53
54
55
56</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/lazier/hash.rb', line 48</span>
<span class='kw'>def</span> <span class='id identifier rubyid_enable_dotted_access'>enable_dotted_access</span><span class='lparen'>(</span><span class='id identifier rubyid_readonly'>readonly</span> <span class='op'>=</span> <span class='kw'>true</span><span class='rparen'>)</span>
<span class='id identifier rubyid_extend'>extend</span><span class='lparen'>(</span><span class='const'>Hashie</span><span class='op'>::</span><span class='const'>Extensions</span><span class='op'>::</span><span class='const'>MethodReader</span><span class='rparen'>)</span>
<span class='id identifier rubyid_extend'>extend</span><span class='lparen'>(</span><span class='const'>Hashie</span><span class='op'>::</span><span class='const'>Extensions</span><span class='op'>::</span><span class='const'>MethodQuery</span><span class='rparen'>)</span>
<span class='id identifier rubyid_extend'>extend</span><span class='lparen'>(</span><span class='const'>Hashie</span><span class='op'>::</span><span class='const'>Extensions</span><span class='op'>::</span><span class='const'>MethodWriter</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='id identifier rubyid_readonly'>readonly</span>
<span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid__'>_</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='op'>|</span> <span class='id identifier rubyid_enable_dotted_access_for_value'>enable_dotted_access_for_value</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='comma'>,</span> <span class='id identifier rubyid_readonly'>readonly</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
<span class='kw'>self</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="ensure_access-instance_method">
#<strong>ensure_access</strong>(*accesses) ⇒ <tt><span class='object_link'><a href="" title="Lazier::Hash (module)">Hash</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Makes sure that the keys of the hash are accessible in the desired way.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>accesses</span>
<span class='type'>(<tt>Array</tt>)</span>
—
<div class='inline'><p>The requested access for the keys. Can be <code>:dotted</code>, <code>:strings</code>, <code>:symbols</code> or <code>:indifferent</code>. If <code>nil</code> the keys are not modified.</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="Lazier::Hash (module)">Hash</a></span></tt>)</span>
—
<div class='inline'><p>The current hash with keys modified.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
39
40
41
42</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/lazier/hash.rb', line 39</span>
<span class='kw'>def</span> <span class='id identifier rubyid_ensure_access'>ensure_access</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_accesses'>accesses</span><span class='rparen'>)</span>
<span class='id identifier rubyid_methods'>methods</span> <span class='op'>=</span> <span class='id identifier rubyid_accesses'>accesses</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>compact:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>flatten:</span> <span class='kw'>true</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_m'>m</span><span class='op'>|</span> <span class='const'>VALID_ACCESSES</span><span class='lbracket'>[</span><span class='id identifier rubyid_m'>m</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span><span class='rbracket'>]</span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span>
<span class='id identifier rubyid_methods'>methods</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='kw'>self</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_a'>a</span><span class='comma'>,</span> <span class='id identifier rubyid_e'>e</span><span class='op'>|</span> <span class='id identifier rubyid_a'>a</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_e'>e</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
</div>
<div id="footer">
Generated on Thu Nov 10 11:39:23 2016 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.5 (ruby-2.3.0).
</div>
</div>
</body>
</html>