inquery 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +0 -2
- data/README.md +11 -2
- data/RUBY_VERSION +1 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/doc/Inquery.html +38 -38
- data/doc/Inquery/Exceptions.html +38 -38
- data/doc/Inquery/Exceptions/Base.html +44 -43
- data/doc/Inquery/Exceptions/InvalidRelation.html +44 -43
- data/doc/Inquery/Exceptions/UnknownCallSignature.html +44 -43
- data/doc/Inquery/Mixins.html +38 -38
- data/doc/Inquery/Mixins/RelationValidation.html +70 -73
- data/doc/Inquery/Mixins/RelationValidation/ClassMethods.html +45 -47
- data/doc/Inquery/Mixins/SchemaValidation.html +47 -45
- data/doc/Inquery/Mixins/SchemaValidation/ClassMethods.html +41 -41
- data/doc/Inquery/Query.html +87 -105
- data/doc/Inquery/Query/Chainable.html +66 -73
- data/doc/_index.html +28 -31
- data/doc/class_list.html +24 -31
- data/doc/css/full_list.css +32 -31
- data/doc/css/style.css +244 -91
- data/doc/file.README.html +135 -143
- data/doc/file_list.html +26 -30
- data/doc/frames.html +7 -16
- data/doc/index.html +135 -143
- data/doc/js/app.js +106 -77
- data/doc/js/full_list.js +170 -135
- data/doc/method_list.html +98 -74
- data/doc/top-level-namespace.html +34 -36
- data/inquery.gemspec +44 -44
- metadata +7 -8
data/doc/file.README.html
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
<!DOCTYPE html
|
2
|
-
|
3
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
4
3
|
<head>
|
5
|
-
<meta
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
6
|
<title>
|
7
7
|
File: README
|
8
8
|
|
9
|
-
— Documentation by YARD 0.
|
9
|
+
— Documentation by YARD 0.9.9
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -15,9 +15,8 @@
|
|
15
15
|
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
16
|
|
17
17
|
<script type="text/javascript" charset="utf-8">
|
18
|
-
|
18
|
+
pathId = "README";
|
19
19
|
relpath = '';
|
20
|
-
framesUrl = "frames.html#!file.README.html";
|
21
20
|
</script>
|
22
21
|
|
23
22
|
|
@@ -28,59 +27,59 @@
|
|
28
27
|
|
29
28
|
</head>
|
30
29
|
<body>
|
31
|
-
<div
|
32
|
-
<
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="file_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
33
38
|
|
34
39
|
<a href="_index.html">Index</a> »
|
35
40
|
<span class="title">File: README</span>
|
36
41
|
|
37
|
-
|
38
|
-
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
39
42
|
</div>
|
40
43
|
|
41
|
-
|
44
|
+
<div id="search">
|
42
45
|
|
43
46
|
<a class="full_list_link" id="class_list_link"
|
44
47
|
href="class_list.html">
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
</a>
|
52
|
-
|
53
|
-
<a class="full_list_link" id="file_list_link"
|
54
|
-
href="file_list.html">
|
55
|
-
File List
|
48
|
+
|
49
|
+
<svg width="24" height="24">
|
50
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
51
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
52
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
</svg>
|
56
54
|
</a>
|
57
55
|
|
58
56
|
</div>
|
59
|
-
|
60
|
-
|
57
|
+
<div class="clear"></div>
|
58
|
+
</div>
|
61
59
|
|
62
|
-
|
60
|
+
<div id="content"><div id='filecontents'><p><a href="https://travis-ci.org/sitrox/inquery"><img src="https://travis-ci.org/sitrox/inquery.svg?branch=master" alt="Build Status"></a>
|
61
|
+
<a href="https://badge.fury.io/rb/inquery"><img src="https://badge.fury.io/rb/inquery.svg" alt="Gem Version"></a></p>
|
63
62
|
|
64
|
-
|
65
|
-
<h1 id="label-Inquery">Inquery</h1>
|
63
|
+
<h1>Inquery</h1>
|
66
64
|
|
67
65
|
<p>A skeleton that allows extracting queries into atomic, reusable classes.</p>
|
68
66
|
|
69
|
-
<h2
|
67
|
+
<h2>Installation</h2>
|
70
68
|
|
71
69
|
<p>To install the <strong>Inquery</strong> gem:</p>
|
72
70
|
|
73
|
-
<pre class="code
|
71
|
+
<pre class="code sh"><code class="sh">$ gem install inquery
|
72
|
+
</code></pre>
|
74
73
|
|
75
|
-
<p>To install it using <code>bundler</code> (recommended for any application),
|
76
|
-
|
74
|
+
<p>To install it using <code>bundler</code> (recommended for any application), add it
|
75
|
+
to your <code>Gemfile</code>:</p>
|
77
76
|
|
78
77
|
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>inquery</span><span class='tstring_end'>'</span></span>
|
79
78
|
</code></pre>
|
80
79
|
|
81
|
-
<h2
|
80
|
+
<h2>Basic usage</h2>
|
82
81
|
|
83
|
-
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>FetchUsersWithACar</span> <span class='op'><</span> <span class='const'>Inquery</span><span class='op'>::</span><span class='const'>Query</span>
|
82
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>FetchUsersWithACar</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="Inquery.html" title="Inquery (module)">Inquery</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Inquery/Query.html" title="Inquery::Query (class)">Query</a></span></span>
|
84
83
|
<span class='id identifier rubyid_schema'>schema</span><span class='lparen'>(</span>
|
85
84
|
<span class='label'>color:</span> <span class='symbol'>:symbol</span>
|
86
85
|
<span class='rparen'>)</span>
|
@@ -94,21 +93,21 @@ add it to your <code>Gemfile</code>:</p>
|
|
94
93
|
<span class='comment'># => [<User id: 1 ...]
|
95
94
|
</span></code></pre>
|
96
95
|
|
97
|
-
<p>Inquery offers its functionality trough two query base classes:
|
98
|
-
|
99
|
-
|
96
|
+
<p>Inquery offers its functionality trough two query base classes: <span class='object_link'><a href="Inquery/Query.html" title="Inquery::Query (class)">Inquery::Query</a></span>
|
97
|
+
and <span class='object_link'><a href="Inquery/Query/Chainable.html" title="Inquery::Query::Chainable (class)">Inquery::Query::Chainable</a></span>. See the following sections for detailed
|
98
|
+
explanations.</p>
|
100
99
|
|
101
|
-
<h2
|
100
|
+
<h2>Basic queries</h2>
|
102
101
|
|
103
|
-
<p>Basic queries inherit from <span class='object_link'><a href="Inquery/Query.html" title="Inquery::Query (class)">Inquery::Query</a></span>. They receive an optional set
|
104
|
-
|
105
|
-
|
106
|
-
|
102
|
+
<p>Basic queries inherit from <span class='object_link'><a href="Inquery/Query.html" title="Inquery::Query (class)">Inquery::Query</a></span>. They receive an optional set of
|
103
|
+
parameters and commonly return a relation / AR result. An optional <code>process</code>
|
104
|
+
method lets you perform additional result processing steps if needed (i.e.
|
105
|
+
converting the result to a hash or similar).</p>
|
107
106
|
|
108
107
|
<p>For this basic functionality, inherit from <span class='object_link'><a href="Inquery/Query.html" title="Inquery::Query (class)">Inquery::Query</a></span> and overwrite
|
109
108
|
the <code>call</code> and optionally the <code>process</code> method:</p>
|
110
109
|
|
111
|
-
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>FetchRedCarsAsJson</span>
|
110
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>FetchRedCarsAsJson</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="Inquery.html" title="Inquery (module)">Inquery</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Inquery/Query.html" title="Inquery::Query (class)">Query</a></span></span>
|
112
111
|
<span class='comment'># The `call` method must be overwritten for every query. It is usually called
|
113
112
|
</span> <span class='comment'># via `run`.
|
114
113
|
</span> <span class='kw'>def</span> <span class='id identifier rubyid_call'>call</span>
|
@@ -139,17 +138,15 @@ the <code>call</code> and optionally the <code>process</code> method:</p>
|
|
139
138
|
</span><span class='const'>FetchRedCarsAsJson</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span>
|
140
139
|
</code></pre>
|
141
140
|
|
142
|
-
<p>Note that it's perfectly fine for some queries to return
|
143
|
-
|
144
|
-
any results.</p>
|
141
|
+
<p>Note that it's perfectly fine for some queries to return <code>nil</code>, i.e. if they're
|
142
|
+
writing queries that don't fetch any results.</p>
|
145
143
|
|
146
|
-
<h2
|
144
|
+
<h2>Chainable queries</h2>
|
147
145
|
|
148
|
-
<p>Chainable queries are queries that input and output an Active Record
|
149
|
-
|
150
|
-
<code>relation</code>:</p>
|
146
|
+
<p>Chainable queries are queries that input and output an Active Record relation.
|
147
|
+
You can access the given relation using the method <code>relation</code>:</p>
|
151
148
|
|
152
|
-
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>Queries</span><span class='op'>::</span><span class='const'>User</span><span class='op'>::</span><span class='const'>FetchActive</span> <span class='op'><</span> <span class='const'>Inquery</span><span class='op'>::</span><span class='const'>Query</span><span class='op'>::</span><span class='const'>Chainable</span>
|
149
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>Queries</span><span class='op'>::</span><span class='const'>User</span><span class='op'>::</span><span class='const'>FetchActive</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="Inquery.html" title="Inquery (module)">Inquery</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Inquery/Query.html" title="Inquery::Query (class)">Query</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Inquery/Query/Chainable.html" title="Inquery::Query::Chainable (class)">Chainable</a></span></span>
|
153
150
|
<span class='kw'>def</span> <span class='id identifier rubyid_call'>call</span>
|
154
151
|
<span class='id identifier rubyid_relation'>relation</span><span class='period'>.</span><span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span><span class='label'>active:</span> <span class='int'>1</span><span class='rparen'>)</span>
|
155
152
|
<span class='kw'>end</span>
|
@@ -157,15 +154,15 @@ relation. You can access the given relation using the method
|
|
157
154
|
</code></pre>
|
158
155
|
|
159
156
|
<p>Input and output relations may or may not be of the same AR class (i.e. you
|
160
|
-
could pass a relation of <code>Group</code>s and receive back a relation of
|
161
|
-
|
157
|
+
could pass a relation of <code>Group</code>s and receive back a relation of corresponding
|
158
|
+
<code>User</code>s).</p>
|
162
159
|
|
163
|
-
<h3
|
160
|
+
<h3>Relation validation</h3>
|
164
161
|
|
165
162
|
<p>Chainable queries allow you to further specify and validate the relation it
|
166
163
|
receives. This is done using the static <code>relation</code> method:</p>
|
167
164
|
|
168
|
-
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>Queries</span><span class='op'>::</span><span class='const'>User</span><span class='op'>::</span><span class='const'>FetchActive</span> <span class='op'><</span> <span class='const'>Inquery</span><span class='op'>::</span><span class='const'>Query</span><span class='op'>::</span><span class='const'>Chainable</span>
|
165
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>Queries</span><span class='op'>::</span><span class='const'>User</span><span class='op'>::</span><span class='const'>FetchActive</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="Inquery.html" title="Inquery (module)">Inquery</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Inquery/Query.html" title="Inquery::Query (class)">Query</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Inquery/Query/Chainable.html" title="Inquery::Query::Chainable (class)">Chainable</a></span></span>
|
169
166
|
<span class='comment'># This will raise an exception when passing a relation which does not
|
170
167
|
</span> <span class='comment'># correspond to the `User` model.
|
171
168
|
</span> <span class='id identifier rubyid_relation'>relation</span> <span class='label'>class:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>User</span><span class='tstring_end'>'</span></span>
|
@@ -175,38 +172,34 @@ receives. This is done using the static <code>relation</code> method:</p>
|
|
175
172
|
</code></pre>
|
176
173
|
|
177
174
|
<p>The <code>relation</code> method accepts the following options:</p>
|
178
|
-
<ul><li>
|
179
|
-
<p><code>class</code></p>
|
180
175
|
|
181
|
-
<
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
</
|
186
|
-
|
176
|
+
<ul>
|
177
|
+
<li><p><code>class</code></p>
|
178
|
+
|
179
|
+
<p>Allows to restrict the class (attribute <code>klass</code>) of the relation.
|
180
|
+
Use <code>nil</code> to not perform any checks. The <code>class</code> attribute will also
|
181
|
+
be taken to infer a default if no relation is given and you didn't
|
182
|
+
specify any <code>default</code>.</p></li>
|
183
|
+
<li><p><code>default</code></p>
|
187
184
|
|
188
185
|
<p>This allows to specify a default relation that will be taken if no relation
|
189
186
|
is given. This must be specified as a Proc returning the relation. Set this
|
190
|
-
to <code>false</code> for no default. If this is set to <code>nil</code>,
|
191
|
-
|
192
|
-
|
193
|
-
</li><li>
|
194
|
-
<p><code>fields</code></p>
|
187
|
+
to <code>false</code> for no default. If this is set to <code>nil</code>, it will try to infer the
|
188
|
+
default from the option <code>class</code> (if given).</p></li>
|
189
|
+
<li><p><code>fields</code></p>
|
195
190
|
|
196
191
|
<p>Allows to restrict the number of fields / values the relation must select.
|
197
|
-
This is particularly useful if you're using the query as a subquery and
|
198
|
-
|
199
|
-
|
200
|
-
</li><li>
|
201
|
-
<p><code>default_select</code></p>
|
192
|
+
This is particularly useful if you're using the query as a subquery and need
|
193
|
+
it to return exactly one field. Use <code>nil</code> to not perform any checks.</p></li>
|
194
|
+
<li><p><code>default_select</code></p>
|
202
195
|
|
203
196
|
<p>If this is set to a symbol, the relation does not have any select fields
|
204
|
-
specified (<code>select_values</code> is empty) and <code>fields</code> is
|
205
|
-
|
206
|
-
|
207
|
-
</
|
197
|
+
specified (<code>select_values</code> is empty) and <code>fields</code> is > 0, it will
|
198
|
+
automatically select the given field. This option defaults to <code>:id</code>. Use
|
199
|
+
<code>nil</code> to disable this behavior.</p></li>
|
200
|
+
</ul>
|
208
201
|
|
209
|
-
<h3
|
202
|
+
<h3>Using query classes as regular scopes</h3>
|
210
203
|
|
211
204
|
<p>Chainable queries can also be used as regular AR model scopes:</p>
|
212
205
|
|
@@ -214,7 +207,7 @@ to <code>:id</code>. Use <code>nil</code> to disable this behavior.</p>
|
|
214
207
|
<span class='id identifier rubyid_scope'>scope</span> <span class='symbol'>:active</span><span class='comma'>,</span> <span class='const'>Queries</span><span class='op'>::</span><span class='const'>User</span><span class='op'>::</span><span class='const'>FetchActive</span>
|
215
208
|
<span class='kw'>end</span>
|
216
209
|
|
217
|
-
<span class='kw'>class</span> <span class='const'>Queries</span><span class='op'>::</span><span class='const'>User</span><span class='op'>::</span><span class='const'>FetchActive</span> <span class='op'><</span> <span class='const'>Inquery</span><span class='op'>::</span><span class='const'>Query</span><span class='op'>::</span><span class='const'>Chainable</span>
|
210
|
+
<span class='kw'>class</span> <span class='const'>Queries</span><span class='op'>::</span><span class='const'>User</span><span class='op'>::</span><span class='const'>FetchActive</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="Inquery.html" title="Inquery (module)">Inquery</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Inquery/Query.html" title="Inquery::Query (class)">Query</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Inquery/Query/Chainable.html" title="Inquery::Query::Chainable (class)">Chainable</a></span></span>
|
218
211
|
<span class='comment'># Note that specifying either `class` or `default` is mandatory when using
|
219
212
|
</span> <span class='comment'># this query class as a scope. The reason for this is that, if the scope is
|
220
213
|
</span> <span class='comment'># otherwise empty, the class will receive `nil` from AR and therefore has no
|
@@ -227,20 +220,18 @@ to <code>:id</code>. Use <code>nil</code> to disable this behavior.</p>
|
|
227
220
|
<span class='kw'>end</span>
|
228
221
|
</code></pre>
|
229
222
|
|
230
|
-
<p>This approach allows to you use short and descriptive code like
|
231
|
-
|
232
|
-
a separate, reusable class.</p>
|
223
|
+
<p>This approach allows to you use short and descriptive code like <code>User.active</code>
|
224
|
+
but have the possibly complex query code hidden in a separate, reusable class.</p>
|
233
225
|
|
234
|
-
<p>Note that when using classes as scopes, the <code>process</code> method
|
235
|
-
will be ignored.</p>
|
226
|
+
<p>Note that when using classes as scopes, the <code>process</code> method will be ignored.</p>
|
236
227
|
|
237
|
-
<h3
|
228
|
+
<h3>Using the given relation as subquery</h3>
|
238
229
|
|
239
|
-
<p>In simple cases and all the examples above, we just extend the given
|
240
|
-
|
241
|
-
|
230
|
+
<p>In simple cases and all the examples above, we just extend the given relation
|
231
|
+
and return it again. It is also possible however to just use the given relation
|
232
|
+
as a subquery and return a completely new relation:</p>
|
242
233
|
|
243
|
-
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>FetchUsersInGroup</span> <span class='op'><</span> <span class='const'>Inquery</span><span class='op'>::</span><span class='const'>Query</span><span class='op'>::</span><span class='const'>Chainable</span>
|
234
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>FetchUsersInGroup</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="Inquery.html" title="Inquery (module)">Inquery</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Inquery/Query.html" title="Inquery::Query (class)">Query</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Inquery/Query/Chainable.html" title="Inquery::Query::Chainable (class)">Chainable</a></span></span>
|
244
235
|
<span class='comment'># Here we do not specify any specific class, as we don't care for it as long
|
245
236
|
</span> <span class='comment'># as the relation returns exactly one field.
|
246
237
|
</span> <span class='id identifier rubyid_relation'>relation</span> <span class='label'>fields:</span> <span class='int'>1</span>
|
@@ -270,15 +261,14 @@ given relation as a subquery and return a completely new relation:</p>
|
|
270
261
|
</span><span class='const'>FetchUsersInGroup</span><span class='period'>.</span><span class='id identifier rubyid_run'>run</span><span class='lparen'>(</span><span class='const'>Group</span><span class='period'>.</span><span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span><span class='label'>color:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>red</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
271
262
|
</code></pre>
|
272
263
|
|
273
|
-
<h2
|
264
|
+
<h2>Parameters</h2>
|
274
265
|
|
275
|
-
<p>Both query classes can be parameterized using a hash called
|
276
|
-
|
277
|
-
|
278
|
-
<
|
279
|
-
href="https://github.com/sitrox/schemacop">Schemacop</a> validation Gem:</p>
|
266
|
+
<p>Both query classes can be parameterized using a hash called <code>params</code>. It is
|
267
|
+
recommended to specify and validate input parameters in every query. For this
|
268
|
+
purpose, Inquery provides the <code>schema</code> method witch integrates the
|
269
|
+
<a href="https://github.com/sitrox/schemacop">Schemacop</a> validation Gem:</p>
|
280
270
|
|
281
|
-
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>SomeQueryClass</span> <span class='op'><</span> <span class='const'>Inquery</span><span class='op'>::</span><span class='const'>Query</span>
|
271
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>SomeQueryClass</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="Inquery.html" title="Inquery (module)">Inquery</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Inquery/Query.html" title="Inquery::Query (class)">Query</a></span></span>
|
282
272
|
<span class='id identifier rubyid_schema'>schema</span><span class='lparen'>(</span>
|
283
273
|
<span class='label'>some_param:</span> <span class='symbol'>:integer</span><span class='comma'>,</span>
|
284
274
|
<span class='label'>some_other_param:</span> <span class='lbrace'>{</span>
|
@@ -293,16 +283,14 @@ href="https://github.com/sitrox/schemacop">Schemacop</a> validation Gem:</p>
|
|
293
283
|
</code></pre>
|
294
284
|
|
295
285
|
<p>The schema is validated at query class instantiation. An exception will be
|
296
|
-
raised if the given params do not match the schema specified. See
|
297
|
-
|
298
|
-
schemas.</p>
|
286
|
+
raised if the given params do not match the schema specified. See documentation
|
287
|
+
of the Schemacop Gem for more information on how to specify schemas.</p>
|
299
288
|
|
300
|
-
<p>Parameters can be accessed using either <code>params</code> or
|
301
|
-
<code>osparams</code
|
302
|
-
<code>params</code> in an <code>OpenStruct</code> for more convenient
|
289
|
+
<p>Parameters can be accessed using either <code>params</code> or <code>osparams</code>. The method
|
290
|
+
<code>osparams</code> automatically wraps <code>params</code> in an <code>OpenStruct</code> for more convenient
|
303
291
|
access.</p>
|
304
292
|
|
305
|
-
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>SomeQueryClass</span> <span class='op'><</span> <span class='const'>Inquery</span><span class='op'>::</span><span class='const'>Query</span>
|
293
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>SomeQueryClass</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="Inquery.html" title="Inquery (module)">Inquery</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Inquery/Query.html" title="Inquery::Query (class)">Query</a></span></span>
|
306
294
|
<span class='kw'>def</span> <span class='id identifier rubyid_run'>run</span>
|
307
295
|
<span class='const'>User</span><span class='period'>.</span><span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span>
|
308
296
|
<span class='label'>active:</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:active</span><span class='rbracket'>]</span><span class='comma'>,</span>
|
@@ -312,54 +300,58 @@ access.</p>
|
|
312
300
|
<span class='kw'>end</span>
|
313
301
|
</code></pre>
|
314
302
|
|
315
|
-
<h2
|
303
|
+
<h2>Rails integration</h2>
|
316
304
|
|
317
305
|
<p>While it is optional, Inquery has been written from the ground up to be
|
318
|
-
perfectly integrated into any Rails application. It has proven to be a
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
<h3
|
323
|
-
|
324
|
-
<p>While not enforced, it is encouraged to use the following structure for
|
325
|
-
|
326
|
-
|
327
|
-
<
|
328
|
-
</li
|
329
|
-
<
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
</li></ul>
|
306
|
+
perfectly integrated into any Rails application. It has proven to be a winning
|
307
|
+
concept to extract all complex queries into separate classes that are
|
308
|
+
independently executable and testable.</p>
|
309
|
+
|
310
|
+
<h3>Directory structure</h3>
|
311
|
+
|
312
|
+
<p>While not enforced, it is encouraged to use the following structure for storing
|
313
|
+
your query classes:</p>
|
314
|
+
|
315
|
+
<ul>
|
316
|
+
<li>All domain-specific query classes reside in <code>app/queries</code>.</li>
|
317
|
+
<li>They're in the module <code>Queries</code>.</li>
|
318
|
+
<li>Queries are further grouped by the model they return (and not the model
|
319
|
+
they receive). For instance, a class fetching all active users could be
|
320
|
+
located at <code>Queries::User::FetchActive</code> and would reside under
|
321
|
+
<code>app/queries/user/fetch_active.rb</code>.</li>
|
322
|
+
</ul>
|
336
323
|
|
337
324
|
<p>There are some key benefits to this approach:</p>
|
338
|
-
|
339
|
-
<
|
340
|
-
|
341
|
-
<
|
342
|
-
they're easy to locate and it does not take much thought where to put
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
</
|
352
|
-
|
353
|
-
<
|
354
|
-
|
355
|
-
|
325
|
+
|
326
|
+
<ul>
|
327
|
+
<li>As it should, domain-specific code is located within <code>app/</code>.</li>
|
328
|
+
<li>As queries are grouped by the model they return and consistently named,
|
329
|
+
they're easy to locate and it does not take much thought where to put and
|
330
|
+
how to name new query classes.</li>
|
331
|
+
<li>As there is a single file per query class, it's a breeze to list all
|
332
|
+
queries, i.e. to check their naming for consistency.</li>
|
333
|
+
<li>If you're using the same layout for your unit tests, it is absolutely
|
334
|
+
clear where to find the corresponding unit tests for each one of your
|
335
|
+
query classes.</li>
|
336
|
+
</ul>
|
337
|
+
|
338
|
+
<h2>Contributors</h2>
|
339
|
+
|
340
|
+
<p>Thanks to Jeroen Weeink for his insights regarding using query classes as scopes
|
341
|
+
in his <a href="http://craftingruby.com/posts/2015/06/29/query-objects-through-scopes.html">blog post</a>.
|
342
|
+
And special thanks to <a href="http://www.subgit.com/">SubGit</a> for their great open source licensing.</p>
|
343
|
+
|
344
|
+
<h2>Copyright</h2>
|
345
|
+
|
346
|
+
<p>Copyright (c) 2017 Sitrox. See <code>LICENSE</code> for further details.</p>
|
356
347
|
</div></div>
|
357
348
|
|
358
|
-
|
359
|
-
Generated on
|
349
|
+
<div id="footer">
|
350
|
+
Generated on Tue May 16 10:49:05 2017 by
|
360
351
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
361
|
-
0.
|
352
|
+
0.9.9 (ruby-2.3.1).
|
362
353
|
</div>
|
363
354
|
|
355
|
+
</div>
|
364
356
|
</body>
|
365
357
|
</html>
|
data/doc/file_list.html
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
<!DOCTYPE html
|
2
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
1
|
+
<!DOCTYPE html>
|
3
2
|
<html>
|
4
3
|
<head>
|
5
|
-
<meta
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
5
|
+
<meta charset="utf-8" />
|
6
6
|
|
7
7
|
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" charset="utf-8" />
|
8
8
|
|
@@ -19,41 +19,37 @@
|
|
19
19
|
<base id="base_target" target="_parent" />
|
20
20
|
</head>
|
21
21
|
<body>
|
22
|
-
<script type="text/javascript" charset="utf-8">
|
23
|
-
var hasFrames = false;
|
24
|
-
try {
|
25
|
-
hasFrames = window.top.frames.main ? true : false;
|
26
|
-
} catch (e) { }
|
27
|
-
if (hasFrames) {
|
28
|
-
document.getElementById('base_target').target = 'main';
|
29
|
-
document.body.className = 'frames';
|
30
|
-
}
|
31
|
-
</script>
|
32
22
|
<div id="content">
|
33
|
-
<
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
23
|
+
<div class="fixed_header">
|
24
|
+
<h1 id="full_list_header">File List</h1>
|
25
|
+
<div id="full_list_nav">
|
26
|
+
|
27
|
+
<span><a target="_self" href="class_list.html">
|
28
|
+
Classes
|
29
|
+
</a></span>
|
30
|
+
|
31
|
+
<span><a target="_self" href="method_list.html">
|
32
|
+
Methods
|
33
|
+
</a></span>
|
34
|
+
|
35
|
+
<span><a target="_self" href="file_list.html">
|
36
|
+
Files
|
37
|
+
</a></span>
|
38
|
+
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="search">Search: <input type="text" /></div>
|
48
42
|
</div>
|
49
|
-
<div id="search">Search: <input type="text" /></div>
|
50
43
|
|
51
44
|
<ul id="full_list" class="file">
|
52
45
|
|
53
46
|
|
54
|
-
<li
|
47
|
+
<li id="object_README" class="odd">
|
48
|
+
<div class="item"><span class="object_link"><a href="index.html" title="README">README</a></span></div>
|
49
|
+
</li>
|
55
50
|
|
56
51
|
|
52
|
+
|
57
53
|
</ul>
|
58
54
|
</div>
|
59
55
|
</body>
|