docs/Bovem/ShellMethods/Read.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Module: Bovem::ShellMethods::Read
— Documentation by YARD 0.9.7
</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 = "Bovem::ShellMethods::Read";
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 (R)</a> »
<span class='title'><span class='object_link'><a href="../../Bovem.html" title="Bovem (module)">Bovem</a></span></span> » <span class='title'><span class='object_link'><a href="../ShellMethods.html" title="Bovem::ShellMethods (module)">ShellMethods</a></span></span>
»
<span class="title">Read</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>Module: Bovem::ShellMethods::Read
</h1>
<div class="box_info">
<dl>
<dt>Included in:</dt>
<dd><span class='object_link'><a href="../Shell.html" title="Bovem::Shell (class)">Bovem::Shell</a></span></dd>
</dl>
<dl>
<dt>Defined in:</dt>
<dd>lib/bovem/shell.rb</dd>
</dl>
</div>
<h2>Overview</h2><div class="docstring">
<div class="discussion">
<p>Methods to find or check entries.</p>
</div>
</div>
<div class="tags">
</div>
<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="#check-instance_method" title="#check (instance method)">#<strong>check</strong>(path, *tests) ⇒ Object </a>
</span>
<span class="summary_desc"><div class='inline'><p>Tests a path against a list of test.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#find-instance_method" title="#find (instance method)">#<strong>find</strong>(directories, patterns: [], extension_only: false, case_sensitive: false, &block) ⇒ Object </a>
</span>
<span class="summary_desc"><div class='inline'><p>Find a list of files in directories matching given regexps or patterns.</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="check-instance_method">
#<strong>check</strong>(path, *tests) ⇒ <tt>Object</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Tests a path against a list of test.</p>
<p>Valid tests are every method available in http://www.ruby-doc.org/core-2.3.0/FileTest.html (plus <code>read</code>, <code>write</code>, <code>execute</code>, <code>exec</code>, <code>dir</code>).
Trailing question mark can be omitted. Unrecognized tests will make the check fail.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>path</span>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>The path to test.</p>
</div>
</li>
<li>
<span class='name'>tests</span>
<span class='type'>(<tt>Array</tt>)</span>
—
<div class='inline'><p>The list of tests to perform.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/bovem/shell.rb', line 51</span>
<span class='kw'>def</span> <span class='id identifier rubyid_check'>check</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_tests'>tests</span><span class='rparen'>)</span>
<span class='id identifier rubyid_path'>path</span> <span class='op'>=</span> <span class='id identifier rubyid_path'>path</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span>
<span class='id identifier rubyid_tests'>tests</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>compact:</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='period'>.</span><span class='id identifier rubyid_all?'>all?</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_test'>test</span><span class='op'>|</span>
<span class='comment'># Adjust test name
</span> <span class='id identifier rubyid_test'>test</span> <span class='op'>=</span> <span class='id identifier rubyid_test'>test</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_strip'>strip</span>
<span class='id identifier rubyid_test'>test</span> <span class='op'>=</span>
<span class='kw'>case</span> <span class='id identifier rubyid_test'>test</span>
<span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>read</span><span class='tstring_end'>"</span></span> <span class='kw'>then</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>readable</span><span class='tstring_end'>"</span></span>
<span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>write</span><span class='tstring_end'>"</span></span> <span class='kw'>then</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>writable</span><span class='tstring_end'>"</span></span>
<span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>execute</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>exec</span><span class='tstring_end'>"</span></span> <span class='kw'>then</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>executable</span><span class='tstring_end'>"</span></span>
<span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>dir</span><span class='tstring_end'>"</span></span> <span class='kw'>then</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>directory</span><span class='tstring_end'>"</span></span>
<span class='kw'>else</span> <span class='id identifier rubyid_test'>test</span>
<span class='kw'>end</span>
<span class='comment'># Execute test
</span> <span class='id identifier rubyid_test'>test</span> <span class='op'>+=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>?</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_test'>test</span> <span class='op'>!~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>\?$</span><span class='regexp_end'>/</span></span>
<span class='const'>FileTest</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='id identifier rubyid_test'>test</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='const'>FileTest</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_test'>test</span><span class='comma'>,</span> <span class='id identifier rubyid_path'>path</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>nil</span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="find-instance_method">
#<strong>find</strong>(directories, patterns: [], extension_only: false, case_sensitive: false, &block) ⇒ <tt>Object</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Find a list of files in directories matching given regexps or patterns.</p>
<p>You can also pass a block to perform matching. The block will receive a single argument and the path will be considered if return value is not falsey.</p>
<p>Inside the block, you can call <code>Find.prune</code> to stop searching in the current directory.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>directories</span>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>A list of directories where to search files.</p>
</div>
</li>
<li>
<span class='name'>patterns</span>
<span class='type'>(<tt>Array</tt>)</span>
—
<div class='inline'><p>A list of regexps or patterns to match files. If empty, every file is returned. Ignored if a block is provided.</p>
</div>
</li>
<li>
<span class='name'>extension_only</span>
<span class='type'>(<tt>Boolean</tt>)</span>
—
<div class='inline'><p>If to only search in extensions. Ignored if a block is provided.</p>
</div>
</li>
<li>
<span class='name'>case_sensitive</span>
<span class='type'>(<tt>Boolean</tt>)</span>
—
<div class='inline'><p>If the search is case sensitive. Only meaningful for string patterns.</p>
</div>
</li>
<li>
<span class='name'>block</span>
<span class='type'>(<tt>Proc</tt>)</span>
—
<div class='inline'><p>An optional block to perform matching instead of pattern matching.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/bovem/shell.rb', line 84</span>
<span class='kw'>def</span> <span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='id identifier rubyid_directories'>directories</span><span class='comma'>,</span> <span class='label'>patterns:</span> <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='label'>extension_only:</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='label'>case_sensitive:</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
<span class='id identifier rubyid_directories'>directories</span> <span class='op'>=</span> <span class='id identifier rubyid_directories'>directories</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>compact:</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_d'>d</span><span class='op'>|</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_expand_path'>expand_path</span><span class='lparen'>(</span><span class='id identifier rubyid_d'>d</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
<span class='id identifier rubyid_patterns'>patterns</span> <span class='op'>=</span> <span class='id identifier rubyid_normalize_patterns'>normalize_patterns</span><span class='lparen'>(</span><span class='id identifier rubyid_patterns'>patterns</span><span class='comma'>,</span> <span class='id identifier rubyid_extension_only'>extension_only</span><span class='comma'>,</span> <span class='id identifier rubyid_case_sensitive'>case_sensitive</span><span class='rparen'>)</span>
<span class='id identifier rubyid_directories'>directories</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_directory'>directory</span><span class='op'>|</span>
<span class='kw'>next</span> <span class='kw'>unless</span> <span class='id identifier rubyid_check'>check</span><span class='lparen'>(</span><span class='id identifier rubyid_directory'>directory</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='symbol'>:directory</span><span class='comma'>,</span> <span class='symbol'>:readable</span><span class='comma'>,</span> <span class='symbol'>:executable</span><span class='rbracket'>]</span><span class='rparen'>)</span>
<span class='const'>Find</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='id identifier rubyid_directory'>directory</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_entry'>entry</span><span class='op'>|</span>
<span class='id identifier rubyid_found'>found</span> <span class='op'>=</span> <span class='id identifier rubyid_patterns'>patterns</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='op'>?</span> <span class='kw'>true</span> <span class='op'>:</span> <span class='id identifier rubyid_match_pattern'>match_pattern</span><span class='lparen'>(</span><span class='id identifier rubyid_entry'>entry</span><span class='comma'>,</span> <span class='id identifier rubyid_patterns'>patterns</span><span class='comma'>,</span> <span class='id identifier rubyid_extension_only'>extension_only</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'><<</span> <span class='id identifier rubyid_entry'>entry</span> <span class='kw'>if</span> <span class='id identifier rubyid_found'>found</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
</div>
<div id="footer">
Generated on Thu Jan 12 16:10:58 2017 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.7 (ruby-2.3.0).
</div>
</div>
</body>
</html>